@codemirror/autocomplete 6.15.0 → 6.16.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 +12 -0
- package/dist/index.cjs +16 -9
- package/dist/index.d.cts +6 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +16 -9
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
## 6.16.1 (2024-05-29)
|
|
2
|
+
|
|
3
|
+
### Bug fixes
|
|
4
|
+
|
|
5
|
+
Fix a bug where multiple backslashes before a brace in a snippet were all removed.
|
|
6
|
+
|
|
7
|
+
## 6.16.0 (2024-04-12)
|
|
8
|
+
|
|
9
|
+
### New features
|
|
10
|
+
|
|
11
|
+
The new `activateOnCompletion` option allows autocompletion to be configured to chain completion activation for some types of completions.
|
|
12
|
+
|
|
1
13
|
## 6.15.0 (2024-03-13)
|
|
2
14
|
|
|
3
15
|
### New features
|
package/dist/index.cjs
CHANGED
|
@@ -348,6 +348,7 @@ const completionConfig = state.Facet.define({
|
|
|
348
348
|
combine(configs) {
|
|
349
349
|
return state.combineConfig(configs, {
|
|
350
350
|
activateOnTyping: true,
|
|
351
|
+
activateOnCompletion: () => false,
|
|
351
352
|
activateOnTypingDelay: 100,
|
|
352
353
|
selectOnOpen: true,
|
|
353
354
|
override: null,
|
|
@@ -882,7 +883,12 @@ function makeAttrs(id, selected) {
|
|
|
882
883
|
return result;
|
|
883
884
|
}
|
|
884
885
|
const none = [];
|
|
885
|
-
function getUserEvent(tr) {
|
|
886
|
+
function getUserEvent(tr, conf) {
|
|
887
|
+
if (tr.isUserEvent("input.complete")) {
|
|
888
|
+
let completion = tr.annotation(pickedCompletion);
|
|
889
|
+
if (completion && conf.activateOnCompletion(completion))
|
|
890
|
+
return "input";
|
|
891
|
+
}
|
|
886
892
|
return tr.isUserEvent("input.type") ? "input" : tr.isUserEvent("delete.backward") ? "delete" : null;
|
|
887
893
|
}
|
|
888
894
|
class ActiveSource {
|
|
@@ -893,7 +899,7 @@ class ActiveSource {
|
|
|
893
899
|
}
|
|
894
900
|
hasResult() { return false; }
|
|
895
901
|
update(tr, conf) {
|
|
896
|
-
let event = getUserEvent(tr), value = this;
|
|
902
|
+
let event = getUserEvent(tr, conf), value = this;
|
|
897
903
|
if (event)
|
|
898
904
|
value = value.handleUserEvent(tr, event, conf);
|
|
899
905
|
else if (tr.docChanged)
|
|
@@ -1072,10 +1078,11 @@ const completionPlugin = view.ViewPlugin.fromClass(class {
|
|
|
1072
1078
|
}
|
|
1073
1079
|
update(update) {
|
|
1074
1080
|
let cState = update.state.field(completionState);
|
|
1081
|
+
let conf = update.state.facet(completionConfig);
|
|
1075
1082
|
if (!update.selectionSet && !update.docChanged && update.startState.field(completionState) == cState)
|
|
1076
1083
|
return;
|
|
1077
1084
|
let doesReset = update.transactions.some(tr => {
|
|
1078
|
-
return (tr.selection || tr.docChanged) && !getUserEvent(tr);
|
|
1085
|
+
return (tr.selection || tr.docChanged) && !getUserEvent(tr, conf);
|
|
1079
1086
|
});
|
|
1080
1087
|
for (let i = 0; i < this.running.length; i++) {
|
|
1081
1088
|
let query = this.running[i];
|
|
@@ -1100,12 +1107,12 @@ const completionPlugin = view.ViewPlugin.fromClass(class {
|
|
|
1100
1107
|
clearTimeout(this.debounceUpdate);
|
|
1101
1108
|
if (update.transactions.some(tr => tr.effects.some(e => e.is(startCompletionEffect))))
|
|
1102
1109
|
this.pendingStart = true;
|
|
1103
|
-
let delay = this.pendingStart ? 50 :
|
|
1110
|
+
let delay = this.pendingStart ? 50 : conf.activateOnTypingDelay;
|
|
1104
1111
|
this.debounceUpdate = cState.active.some(a => a.state == 1 /* State.Pending */ && !this.running.some(q => q.active.source == a.source))
|
|
1105
1112
|
? setTimeout(() => this.startUpdate(), delay) : -1;
|
|
1106
1113
|
if (this.composing != 0 /* CompositionState.None */)
|
|
1107
1114
|
for (let tr of update.transactions) {
|
|
1108
|
-
if (getUserEvent(tr) == "input")
|
|
1115
|
+
if (getUserEvent(tr, conf) == "input")
|
|
1109
1116
|
this.composing = 2 /* CompositionState.Changed */;
|
|
1110
1117
|
else if (this.composing == 2 /* CompositionState.Changed */ && tr.selection)
|
|
1111
1118
|
this.composing = 3 /* CompositionState.ChangedAndMoved */;
|
|
@@ -1413,14 +1420,14 @@ class Snippet {
|
|
|
1413
1420
|
positions.push(new FieldPos(found, lines.length, m.index, m.index + name.length));
|
|
1414
1421
|
line = line.slice(0, m.index) + name + line.slice(m.index + m[0].length);
|
|
1415
1422
|
}
|
|
1416
|
-
|
|
1417
|
-
line = line.slice(0, esc.index) + esc[1] + line.slice(esc.index + esc[0].length);
|
|
1423
|
+
line = line.replace(/\\([{}])/g, (_, brace, index) => {
|
|
1418
1424
|
for (let pos of positions)
|
|
1419
|
-
if (pos.line == lines.length && pos.from >
|
|
1425
|
+
if (pos.line == lines.length && pos.from > index) {
|
|
1420
1426
|
pos.from--;
|
|
1421
1427
|
pos.to--;
|
|
1422
1428
|
}
|
|
1423
|
-
|
|
1429
|
+
return brace;
|
|
1430
|
+
});
|
|
1424
1431
|
lines.push(line);
|
|
1425
1432
|
}
|
|
1426
1433
|
return new Snippet(lines, positions);
|
package/dist/index.d.cts
CHANGED
|
@@ -294,6 +294,11 @@ interface CompletionConfig {
|
|
|
294
294
|
*/
|
|
295
295
|
activateOnTyping?: boolean;
|
|
296
296
|
/**
|
|
297
|
+
When given, if a completion that matches the predicate is
|
|
298
|
+
picked, reactivate completion again as if it was typed normally.
|
|
299
|
+
*/
|
|
300
|
+
activateOnCompletion?: (completion: Completion) => boolean;
|
|
301
|
+
/**
|
|
297
302
|
The amount of time to wait for further typing before querying
|
|
298
303
|
completion sources via
|
|
299
304
|
[`activateOnTyping`](https://codemirror.net/6/docs/ref/#autocomplete.autocompletion^config.activateOnTyping).
|
|
@@ -517,7 +522,7 @@ interface CloseBracketConfig {
|
|
|
517
522
|
/**
|
|
518
523
|
The opening brackets to close. Defaults to `["(", "[", "{", "'",
|
|
519
524
|
'"']`. Brackets may be single characters or a triple of quotes
|
|
520
|
-
(as in `"'''
|
|
525
|
+
(as in `"'''"`).
|
|
521
526
|
*/
|
|
522
527
|
brackets?: string[];
|
|
523
528
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -294,6 +294,11 @@ interface CompletionConfig {
|
|
|
294
294
|
*/
|
|
295
295
|
activateOnTyping?: boolean;
|
|
296
296
|
/**
|
|
297
|
+
When given, if a completion that matches the predicate is
|
|
298
|
+
picked, reactivate completion again as if it was typed normally.
|
|
299
|
+
*/
|
|
300
|
+
activateOnCompletion?: (completion: Completion) => boolean;
|
|
301
|
+
/**
|
|
297
302
|
The amount of time to wait for further typing before querying
|
|
298
303
|
completion sources via
|
|
299
304
|
[`activateOnTyping`](https://codemirror.net/6/docs/ref/#autocomplete.autocompletion^config.activateOnTyping).
|
|
@@ -517,7 +522,7 @@ interface CloseBracketConfig {
|
|
|
517
522
|
/**
|
|
518
523
|
The opening brackets to close. Defaults to `["(", "[", "{", "'",
|
|
519
524
|
'"']`. Brackets may be single characters or a triple of quotes
|
|
520
|
-
(as in `"'''
|
|
525
|
+
(as in `"'''"`).
|
|
521
526
|
*/
|
|
522
527
|
brackets?: string[];
|
|
523
528
|
/**
|
package/dist/index.js
CHANGED
|
@@ -346,6 +346,7 @@ const completionConfig = /*@__PURE__*/Facet.define({
|
|
|
346
346
|
combine(configs) {
|
|
347
347
|
return combineConfig(configs, {
|
|
348
348
|
activateOnTyping: true,
|
|
349
|
+
activateOnCompletion: () => false,
|
|
349
350
|
activateOnTypingDelay: 100,
|
|
350
351
|
selectOnOpen: true,
|
|
351
352
|
override: null,
|
|
@@ -880,7 +881,12 @@ function makeAttrs(id, selected) {
|
|
|
880
881
|
return result;
|
|
881
882
|
}
|
|
882
883
|
const none = [];
|
|
883
|
-
function getUserEvent(tr) {
|
|
884
|
+
function getUserEvent(tr, conf) {
|
|
885
|
+
if (tr.isUserEvent("input.complete")) {
|
|
886
|
+
let completion = tr.annotation(pickedCompletion);
|
|
887
|
+
if (completion && conf.activateOnCompletion(completion))
|
|
888
|
+
return "input";
|
|
889
|
+
}
|
|
884
890
|
return tr.isUserEvent("input.type") ? "input" : tr.isUserEvent("delete.backward") ? "delete" : null;
|
|
885
891
|
}
|
|
886
892
|
class ActiveSource {
|
|
@@ -891,7 +897,7 @@ class ActiveSource {
|
|
|
891
897
|
}
|
|
892
898
|
hasResult() { return false; }
|
|
893
899
|
update(tr, conf) {
|
|
894
|
-
let event = getUserEvent(tr), value = this;
|
|
900
|
+
let event = getUserEvent(tr, conf), value = this;
|
|
895
901
|
if (event)
|
|
896
902
|
value = value.handleUserEvent(tr, event, conf);
|
|
897
903
|
else if (tr.docChanged)
|
|
@@ -1070,10 +1076,11 @@ const completionPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
|
|
|
1070
1076
|
}
|
|
1071
1077
|
update(update) {
|
|
1072
1078
|
let cState = update.state.field(completionState);
|
|
1079
|
+
let conf = update.state.facet(completionConfig);
|
|
1073
1080
|
if (!update.selectionSet && !update.docChanged && update.startState.field(completionState) == cState)
|
|
1074
1081
|
return;
|
|
1075
1082
|
let doesReset = update.transactions.some(tr => {
|
|
1076
|
-
return (tr.selection || tr.docChanged) && !getUserEvent(tr);
|
|
1083
|
+
return (tr.selection || tr.docChanged) && !getUserEvent(tr, conf);
|
|
1077
1084
|
});
|
|
1078
1085
|
for (let i = 0; i < this.running.length; i++) {
|
|
1079
1086
|
let query = this.running[i];
|
|
@@ -1098,12 +1105,12 @@ const completionPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
|
|
|
1098
1105
|
clearTimeout(this.debounceUpdate);
|
|
1099
1106
|
if (update.transactions.some(tr => tr.effects.some(e => e.is(startCompletionEffect))))
|
|
1100
1107
|
this.pendingStart = true;
|
|
1101
|
-
let delay = this.pendingStart ? 50 :
|
|
1108
|
+
let delay = this.pendingStart ? 50 : conf.activateOnTypingDelay;
|
|
1102
1109
|
this.debounceUpdate = cState.active.some(a => a.state == 1 /* State.Pending */ && !this.running.some(q => q.active.source == a.source))
|
|
1103
1110
|
? setTimeout(() => this.startUpdate(), delay) : -1;
|
|
1104
1111
|
if (this.composing != 0 /* CompositionState.None */)
|
|
1105
1112
|
for (let tr of update.transactions) {
|
|
1106
|
-
if (getUserEvent(tr) == "input")
|
|
1113
|
+
if (getUserEvent(tr, conf) == "input")
|
|
1107
1114
|
this.composing = 2 /* CompositionState.Changed */;
|
|
1108
1115
|
else if (this.composing == 2 /* CompositionState.Changed */ && tr.selection)
|
|
1109
1116
|
this.composing = 3 /* CompositionState.ChangedAndMoved */;
|
|
@@ -1411,14 +1418,14 @@ class Snippet {
|
|
|
1411
1418
|
positions.push(new FieldPos(found, lines.length, m.index, m.index + name.length));
|
|
1412
1419
|
line = line.slice(0, m.index) + name + line.slice(m.index + m[0].length);
|
|
1413
1420
|
}
|
|
1414
|
-
|
|
1415
|
-
line = line.slice(0, esc.index) + esc[1] + line.slice(esc.index + esc[0].length);
|
|
1421
|
+
line = line.replace(/\\([{}])/g, (_, brace, index) => {
|
|
1416
1422
|
for (let pos of positions)
|
|
1417
|
-
if (pos.line == lines.length && pos.from >
|
|
1423
|
+
if (pos.line == lines.length && pos.from > index) {
|
|
1418
1424
|
pos.from--;
|
|
1419
1425
|
pos.to--;
|
|
1420
1426
|
}
|
|
1421
|
-
|
|
1427
|
+
return brace;
|
|
1428
|
+
});
|
|
1422
1429
|
lines.push(line);
|
|
1423
1430
|
}
|
|
1424
1431
|
return new Snippet(lines, positions);
|