@codemirror/autocomplete 0.20.0 → 0.20.1
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 +8 -0
- package/dist/index.cjs +15 -2
- package/dist/index.d.ts +13 -0
- package/dist/index.js +15 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
## 0.20.1 (2022-05-16)
|
|
2
|
+
|
|
3
|
+
### New features
|
|
4
|
+
|
|
5
|
+
The new `closeOnBlur` option determines whether the completion tooltip is closed when the editor loses focus.
|
|
6
|
+
|
|
7
|
+
`CompletionResult` objects with `filter: false` may now have a `getMatch` property that determines the matched range in the options.
|
|
8
|
+
|
|
1
9
|
## 0.20.0 (2022-04-20)
|
|
2
10
|
|
|
3
11
|
### Breaking changes
|
package/dist/index.cjs
CHANGED
|
@@ -320,6 +320,7 @@ const completionConfig = state.Facet.define({
|
|
|
320
320
|
return state.combineConfig(configs, {
|
|
321
321
|
activateOnTyping: true,
|
|
322
322
|
override: null,
|
|
323
|
+
closeOnBlur: true,
|
|
323
324
|
maxRenderedOptions: 100,
|
|
324
325
|
defaultKeymap: true,
|
|
325
326
|
optionClass: () => "",
|
|
@@ -328,6 +329,7 @@ const completionConfig = state.Facet.define({
|
|
|
328
329
|
addToOptions: []
|
|
329
330
|
}, {
|
|
330
331
|
defaultKeymap: (a, b) => a && b,
|
|
332
|
+
closeOnBlur: (a, b) => a && b,
|
|
331
333
|
icons: (a, b) => a && b,
|
|
332
334
|
optionClass: (a, b) => c => joinClass(a(c), b(c)),
|
|
333
335
|
addToOptions: (a, b) => a.concat(b)
|
|
@@ -573,8 +575,14 @@ function sortOptions(active, state) {
|
|
|
573
575
|
for (let a of active)
|
|
574
576
|
if (a.hasResult()) {
|
|
575
577
|
if (a.result.filter === false) {
|
|
576
|
-
|
|
577
|
-
|
|
578
|
+
let getMatch = a.result.getMatch;
|
|
579
|
+
for (let option of a.result.options) {
|
|
580
|
+
let match = [1e9 - i++];
|
|
581
|
+
if (getMatch)
|
|
582
|
+
for (let n of getMatch(option))
|
|
583
|
+
match.push(n);
|
|
584
|
+
options.push(new Option(option, a, match));
|
|
585
|
+
}
|
|
578
586
|
}
|
|
579
587
|
else {
|
|
580
588
|
let matcher = new FuzzyMatcher(state.sliceDoc(a.from, a.to)), match;
|
|
@@ -982,6 +990,11 @@ const completionPlugin = view.ViewPlugin.fromClass(class {
|
|
|
982
990
|
}
|
|
983
991
|
}, {
|
|
984
992
|
eventHandlers: {
|
|
993
|
+
blur() {
|
|
994
|
+
let state = this.view.state.field(completionState, false);
|
|
995
|
+
if (state && state.tooltip && this.view.state.facet(completionConfig).closeOnBlur)
|
|
996
|
+
this.view.dispatch({ effects: closeCompletionEffect.of(null) });
|
|
997
|
+
},
|
|
985
998
|
compositionstart() {
|
|
986
999
|
this.composing = 1 /* Started */;
|
|
987
1000
|
},
|
package/dist/index.d.ts
CHANGED
|
@@ -18,6 +18,11 @@ interface CompletionConfig {
|
|
|
18
18
|
*/
|
|
19
19
|
override?: readonly CompletionSource[] | null;
|
|
20
20
|
/**
|
|
21
|
+
Determines whether the completion tooltip is closed when the
|
|
22
|
+
editor loses focus. Defaults to true.
|
|
23
|
+
*/
|
|
24
|
+
closeOnBlur?: boolean;
|
|
25
|
+
/**
|
|
21
26
|
The maximum number of options to render to the DOM.
|
|
22
27
|
*/
|
|
23
28
|
maxRenderedOptions?: number;
|
|
@@ -243,6 +248,14 @@ interface CompletionResult {
|
|
|
243
248
|
*/
|
|
244
249
|
filter?: boolean;
|
|
245
250
|
/**
|
|
251
|
+
When [`filter`](https://codemirror.net/6/docs/ref/#autocomplete.CompletionResult.filter) is set to
|
|
252
|
+
`false`, this may be provided to compute the ranges on the label
|
|
253
|
+
that match the input. Should return an array of numbers where
|
|
254
|
+
each pair of adjacent numbers provide the start and end of a
|
|
255
|
+
range.
|
|
256
|
+
*/
|
|
257
|
+
getMatch?: (completion: Completion) => readonly number[];
|
|
258
|
+
/**
|
|
246
259
|
Synchronously update the completion result after typing or
|
|
247
260
|
deletion. If given, this should not do any expensive work, since
|
|
248
261
|
it will be called during editor state updates. The function
|
package/dist/index.js
CHANGED
|
@@ -316,6 +316,7 @@ const completionConfig = /*@__PURE__*/Facet.define({
|
|
|
316
316
|
return combineConfig(configs, {
|
|
317
317
|
activateOnTyping: true,
|
|
318
318
|
override: null,
|
|
319
|
+
closeOnBlur: true,
|
|
319
320
|
maxRenderedOptions: 100,
|
|
320
321
|
defaultKeymap: true,
|
|
321
322
|
optionClass: () => "",
|
|
@@ -324,6 +325,7 @@ const completionConfig = /*@__PURE__*/Facet.define({
|
|
|
324
325
|
addToOptions: []
|
|
325
326
|
}, {
|
|
326
327
|
defaultKeymap: (a, b) => a && b,
|
|
328
|
+
closeOnBlur: (a, b) => a && b,
|
|
327
329
|
icons: (a, b) => a && b,
|
|
328
330
|
optionClass: (a, b) => c => joinClass(a(c), b(c)),
|
|
329
331
|
addToOptions: (a, b) => a.concat(b)
|
|
@@ -569,8 +571,14 @@ function sortOptions(active, state) {
|
|
|
569
571
|
for (let a of active)
|
|
570
572
|
if (a.hasResult()) {
|
|
571
573
|
if (a.result.filter === false) {
|
|
572
|
-
|
|
573
|
-
|
|
574
|
+
let getMatch = a.result.getMatch;
|
|
575
|
+
for (let option of a.result.options) {
|
|
576
|
+
let match = [1e9 - i++];
|
|
577
|
+
if (getMatch)
|
|
578
|
+
for (let n of getMatch(option))
|
|
579
|
+
match.push(n);
|
|
580
|
+
options.push(new Option(option, a, match));
|
|
581
|
+
}
|
|
574
582
|
}
|
|
575
583
|
else {
|
|
576
584
|
let matcher = new FuzzyMatcher(state.sliceDoc(a.from, a.to)), match;
|
|
@@ -978,6 +986,11 @@ const completionPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
|
|
|
978
986
|
}
|
|
979
987
|
}, {
|
|
980
988
|
eventHandlers: {
|
|
989
|
+
blur() {
|
|
990
|
+
let state = this.view.state.field(completionState, false);
|
|
991
|
+
if (state && state.tooltip && this.view.state.facet(completionConfig).closeOnBlur)
|
|
992
|
+
this.view.dispatch({ effects: closeCompletionEffect.of(null) });
|
|
993
|
+
},
|
|
981
994
|
compositionstart() {
|
|
982
995
|
this.composing = 1 /* Started */;
|
|
983
996
|
},
|