@codemirror/autocomplete 6.18.3 → 6.18.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ## 6.18.5 (2025-02-11)
2
+
3
+ ### Bug fixes
4
+
5
+ Fix an issue where clicking on the scrollbar for the completion list could move focus out of the editor.
6
+
7
+ ## 6.18.4 (2024-12-17)
8
+
9
+ ### Bug fixes
10
+
11
+ Align the behavior of snippet completions with text completions in that they overwrite the selected text.
12
+
1
13
  ## 6.18.3 (2024-11-13)
2
14
 
3
15
  ### Bug fixes
package/README.md CHANGED
@@ -16,3 +16,28 @@ We aim to be an inclusive, welcoming community. To make that explicit,
16
16
  we have a [code of
17
17
  conduct](http://contributor-covenant.org/version/1/1/0/) that applies
18
18
  to communication around the project.
19
+
20
+ ## Usage
21
+
22
+ ```javascript
23
+ import {EditorView} from "@codemirror/view"
24
+ import {autocompletion} from "@codemirror/autocomplete"
25
+ import {jsonLanguage} from "@codemirror/lang-json"
26
+
27
+ const view = new EditorView({
28
+ parent: document.body,
29
+ extensions: [
30
+ jsonLanguage,
31
+ autocompletion(),
32
+ jsonLanguage.data.of({
33
+ autocomplete: ["id", "name", "address"]
34
+ })
35
+ ]
36
+ })
37
+ ```
38
+
39
+ This configuration will just complete the given words anywhere in JSON
40
+ context. Most language modules come with more refined autocompletion
41
+ built-in, but you can also write your own custom autocompletion
42
+ [sources](https://codemirror.net/docs/ref/#autocomplete.CompletionSource)
43
+ and associate them with your language this way.
package/dist/index.cjs CHANGED
@@ -652,8 +652,8 @@ class CompletionTooltip {
652
652
  let selRect = sel.getBoundingClientRect();
653
653
  let space = this.space;
654
654
  if (!space) {
655
- let win = this.dom.ownerDocument.defaultView || window;
656
- space = { left: 0, top: 0, right: win.innerWidth, bottom: win.innerHeight };
655
+ let docElt = this.dom.ownerDocument.documentElement;
656
+ space = { left: 0, top: 0, right: docElt.clientWidth, bottom: docElt.clientHeight };
657
657
  }
658
658
  if (selRect.top > Math.min(space.bottom, listRect.bottom) - 10 ||
659
659
  selRect.bottom < Math.max(space.top, listRect.top) + 10)
@@ -678,6 +678,11 @@ class CompletionTooltip {
678
678
  ul.setAttribute("role", "listbox");
679
679
  ul.setAttribute("aria-expanded", "true");
680
680
  ul.setAttribute("aria-label", this.view.state.phrase("Completions"));
681
+ ul.addEventListener("mousedown", e => {
682
+ // Prevent focus change when clicking the scrollbar
683
+ if (e.target == ul)
684
+ e.preventDefault();
685
+ });
681
686
  let curSection = null;
682
687
  for (let i = range.from; i < range.to; i++) {
683
688
  let { completion, match } = options[i], { section } = completion;
@@ -1560,8 +1565,9 @@ function snippet(template) {
1560
1565
  let snippet = Snippet.parse(template);
1561
1566
  return (editor, completion, from, to) => {
1562
1567
  let { text, ranges } = snippet.instantiate(editor.state, from);
1568
+ let { main } = editor.state.selection;
1563
1569
  let spec = {
1564
- changes: { from, to, insert: state.Text.of(text) },
1570
+ changes: { from, to: to == main.from ? main.to : to, insert: state.Text.of(text) },
1565
1571
  scrollIntoView: true,
1566
1572
  annotations: completion ? [pickedCompletion.of(completion), state.Transaction.userEvent.of("input.complete")] : undefined
1567
1573
  };
package/dist/index.js CHANGED
@@ -650,8 +650,8 @@ class CompletionTooltip {
650
650
  let selRect = sel.getBoundingClientRect();
651
651
  let space = this.space;
652
652
  if (!space) {
653
- let win = this.dom.ownerDocument.defaultView || window;
654
- space = { left: 0, top: 0, right: win.innerWidth, bottom: win.innerHeight };
653
+ let docElt = this.dom.ownerDocument.documentElement;
654
+ space = { left: 0, top: 0, right: docElt.clientWidth, bottom: docElt.clientHeight };
655
655
  }
656
656
  if (selRect.top > Math.min(space.bottom, listRect.bottom) - 10 ||
657
657
  selRect.bottom < Math.max(space.top, listRect.top) + 10)
@@ -676,6 +676,11 @@ class CompletionTooltip {
676
676
  ul.setAttribute("role", "listbox");
677
677
  ul.setAttribute("aria-expanded", "true");
678
678
  ul.setAttribute("aria-label", this.view.state.phrase("Completions"));
679
+ ul.addEventListener("mousedown", e => {
680
+ // Prevent focus change when clicking the scrollbar
681
+ if (e.target == ul)
682
+ e.preventDefault();
683
+ });
679
684
  let curSection = null;
680
685
  for (let i = range.from; i < range.to; i++) {
681
686
  let { completion, match } = options[i], { section } = completion;
@@ -1558,8 +1563,9 @@ function snippet(template) {
1558
1563
  let snippet = Snippet.parse(template);
1559
1564
  return (editor, completion, from, to) => {
1560
1565
  let { text, ranges } = snippet.instantiate(editor.state, from);
1566
+ let { main } = editor.state.selection;
1561
1567
  let spec = {
1562
- changes: { from, to, insert: Text.of(text) },
1568
+ changes: { from, to: to == main.from ? main.to : to, insert: Text.of(text) },
1563
1569
  scrollIntoView: true,
1564
1570
  annotations: completion ? [pickedCompletion.of(completion), Transaction.userEvent.of("input.complete")] : undefined
1565
1571
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemirror/autocomplete",
3
- "version": "6.18.3",
3
+ "version": "6.18.5",
4
4
  "description": "Autocompletion for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",
@@ -31,12 +31,6 @@
31
31
  "@codemirror/view": "^6.17.0",
32
32
  "@lezer/common": "^1.0.0"
33
33
  },
34
- "peerDependencies": {
35
- "@codemirror/language": "^6.0.0",
36
- "@codemirror/state": "^6.0.0",
37
- "@codemirror/view": "^6.0.0",
38
- "@lezer/common": "^1.0.0"
39
- },
40
34
  "devDependencies": {
41
35
  "@codemirror/buildhelper": "^1.0.0"
42
36
  },