@codemirror/autocomplete 6.18.4 → 6.18.6

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.6 (2025-02-12)
2
+
3
+ ### Bug fixes
4
+
5
+ Fix an issue where the closing character for double-angle quotation marks and full-width brackets was computed incorrectly.
6
+
7
+ ## 6.18.5 (2025-02-11)
8
+
9
+ ### Bug fixes
10
+
11
+ Fix an issue where clicking on the scrollbar for the completion list could move focus out of the editor.
12
+
1
13
  ## 6.18.4 (2024-12-17)
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;
@@ -1782,7 +1787,7 @@ that bracket.
1782
1787
  function closeBrackets() {
1783
1788
  return [inputHandler, bracketState];
1784
1789
  }
1785
- const definedClosing = "()[]{}<>";
1790
+ const definedClosing = "()[]{}<>«»»«[]{}";
1786
1791
  function closing(ch) {
1787
1792
  for (let i = 0; i < definedClosing.length; i += 2)
1788
1793
  if (definedClosing.charCodeAt(i) == ch)
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;
@@ -1780,7 +1785,7 @@ that bracket.
1780
1785
  function closeBrackets() {
1781
1786
  return [inputHandler, bracketState];
1782
1787
  }
1783
- const definedClosing = "()[]{}<>";
1788
+ const definedClosing = "()[]{}<>«»»«[]{}";
1784
1789
  function closing(ch) {
1785
1790
  for (let i = 0; i < definedClosing.length; i += 2)
1786
1791
  if (definedClosing.charCodeAt(i) == ch)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemirror/autocomplete",
3
- "version": "6.18.4",
3
+ "version": "6.18.6",
4
4
  "description": "Autocompletion for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",