@codemirror/autocomplete 6.18.4 → 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 +6 -0
- package/README.md +25 -0
- package/dist/index.cjs +7 -2
- package/dist/index.js +7 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
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
|
|
656
|
-
space = { left: 0, top: 0, right:
|
|
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;
|
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
|
|
654
|
-
space = { left: 0, top: 0, right:
|
|
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;
|