@codemirror/autocomplete 6.17.0 → 6.18.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 +18 -0
- package/dist/index.cjs +25 -6
- package/dist/index.d.cts +13 -3
- package/dist/index.d.ts +13 -3
- package/dist/index.js +25 -6
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
## 6.18.1 (2024-09-14)
|
|
2
|
+
|
|
3
|
+
### Bug fixes
|
|
4
|
+
|
|
5
|
+
Fix an issue where `insertCompletionText` would get confused about the length of the inserted text when it contained CRLF line breaks, and create an invalid selection.
|
|
6
|
+
|
|
7
|
+
Add Alt-Backtick as additional binding on macOS, where IME can take over Ctrl-Space.
|
|
8
|
+
|
|
9
|
+
## 6.18.0 (2024-08-05)
|
|
10
|
+
|
|
11
|
+
### Bug fixes
|
|
12
|
+
|
|
13
|
+
Style the info element so that newlines are preserved, to make it easier to display multi-line info from a string source.
|
|
14
|
+
|
|
15
|
+
### New features
|
|
16
|
+
|
|
17
|
+
When registering an `abort` handler for a completion query, you can now use the `onDocChange` option to indicate that your query should be aborted as soon as the document changes while it is running.
|
|
18
|
+
|
|
1
19
|
## 6.17.0 (2024-07-03)
|
|
2
20
|
|
|
3
21
|
### Bug fixes
|
package/dist/index.cjs
CHANGED
|
@@ -45,6 +45,10 @@ class CompletionContext {
|
|
|
45
45
|
@internal
|
|
46
46
|
*/
|
|
47
47
|
this.abortListeners = [];
|
|
48
|
+
/**
|
|
49
|
+
@internal
|
|
50
|
+
*/
|
|
51
|
+
this.abortOnDocChange = false;
|
|
48
52
|
}
|
|
49
53
|
/**
|
|
50
54
|
Get the extent, content, and (if there is a token) type of the
|
|
@@ -78,10 +82,21 @@ class CompletionContext {
|
|
|
78
82
|
Allows you to register abort handlers, which will be called when
|
|
79
83
|
the query is
|
|
80
84
|
[aborted](https://codemirror.net/6/docs/ref/#autocomplete.CompletionContext.aborted).
|
|
85
|
+
|
|
86
|
+
By default, running queries will not be aborted for regular
|
|
87
|
+
typing or backspacing, on the assumption that they are likely to
|
|
88
|
+
return a result with a
|
|
89
|
+
[`validFor`](https://codemirror.net/6/docs/ref/#autocomplete.CompletionResult.validFor) field that
|
|
90
|
+
allows the result to be used after all. Passing `onDocChange:
|
|
91
|
+
true` will cause this query to be aborted for any document
|
|
92
|
+
change.
|
|
81
93
|
*/
|
|
82
|
-
addEventListener(type, listener) {
|
|
83
|
-
if (type == "abort" && this.abortListeners)
|
|
94
|
+
addEventListener(type, listener, options) {
|
|
95
|
+
if (type == "abort" && this.abortListeners) {
|
|
84
96
|
this.abortListeners.push(listener);
|
|
97
|
+
if (options && options.onDocChange)
|
|
98
|
+
this.abortOnDocChange = true;
|
|
99
|
+
}
|
|
85
100
|
}
|
|
86
101
|
}
|
|
87
102
|
function toSet(chars) {
|
|
@@ -178,9 +193,10 @@ function insertCompletionText(state$1, text, from, to) {
|
|
|
178
193
|
if (range != main && from != to &&
|
|
179
194
|
state$1.sliceDoc(range.from + fromOff, range.from + toOff) != state$1.sliceDoc(from, to))
|
|
180
195
|
return { range };
|
|
196
|
+
let lines = state$1.toText(text);
|
|
181
197
|
return {
|
|
182
|
-
changes: { from: range.from + fromOff, to: to == main.from ? range.to : range.from + toOff, insert:
|
|
183
|
-
range: state.EditorSelection.cursor(range.from + fromOff +
|
|
198
|
+
changes: { from: range.from + fromOff, to: to == main.from ? range.to : range.from + toOff, insert: lines },
|
|
199
|
+
range: state.EditorSelection.cursor(range.from + fromOff + lines.length)
|
|
184
200
|
};
|
|
185
201
|
})), { scrollIntoView: true, userEvent: "input.complete" });
|
|
186
202
|
}
|
|
@@ -1102,6 +1118,7 @@ const completionPlugin = view.ViewPlugin.fromClass(class {
|
|
|
1102
1118
|
for (let i = 0; i < this.running.length; i++) {
|
|
1103
1119
|
let query = this.running[i];
|
|
1104
1120
|
if (doesReset ||
|
|
1121
|
+
query.context.abortOnDocChange && update.docChanged ||
|
|
1105
1122
|
query.updates.length + update.transactions.length > MaxUpdateCount && Date.now() - query.time > MinAbortTime) {
|
|
1106
1123
|
for (let handler of query.context.abortListeners) {
|
|
1107
1124
|
try {
|
|
@@ -1303,7 +1320,8 @@ const baseTheme = view.EditorView.baseTheme({
|
|
|
1303
1320
|
padding: "3px 9px",
|
|
1304
1321
|
width: "max-content",
|
|
1305
1322
|
maxWidth: `${400 /* Info.Width */}px`,
|
|
1306
|
-
boxSizing: "border-box"
|
|
1323
|
+
boxSizing: "border-box",
|
|
1324
|
+
whiteSpace: "pre-line"
|
|
1307
1325
|
},
|
|
1308
1326
|
".cm-completionInfo.cm-completionInfo-left": { right: "100%" },
|
|
1309
1327
|
".cm-completionInfo.cm-completionInfo-right": { left: "100%" },
|
|
@@ -1979,7 +1997,7 @@ function autocompletion(config = {}) {
|
|
|
1979
1997
|
/**
|
|
1980
1998
|
Basic keybindings for autocompletion.
|
|
1981
1999
|
|
|
1982
|
-
- Ctrl-Space: [`startCompletion`](https://codemirror.net/6/docs/ref/#autocomplete.startCompletion)
|
|
2000
|
+
- Ctrl-Space (and Alt-\` on macOS): [`startCompletion`](https://codemirror.net/6/docs/ref/#autocomplete.startCompletion)
|
|
1983
2001
|
- Escape: [`closeCompletion`](https://codemirror.net/6/docs/ref/#autocomplete.closeCompletion)
|
|
1984
2002
|
- ArrowDown: [`moveCompletionSelection`](https://codemirror.net/6/docs/ref/#autocomplete.moveCompletionSelection)`(true)`
|
|
1985
2003
|
- ArrowUp: [`moveCompletionSelection`](https://codemirror.net/6/docs/ref/#autocomplete.moveCompletionSelection)`(false)`
|
|
@@ -1989,6 +2007,7 @@ Basic keybindings for autocompletion.
|
|
|
1989
2007
|
*/
|
|
1990
2008
|
const completionKeymap = [
|
|
1991
2009
|
{ key: "Ctrl-Space", run: startCompletion },
|
|
2010
|
+
{ mac: "Alt-`", run: startCompletion },
|
|
1992
2011
|
{ key: "Escape", run: closeCompletion },
|
|
1993
2012
|
{ key: "ArrowDown", run: moveCompletionSelection(true) },
|
|
1994
2013
|
{ key: "ArrowUp", run: moveCompletionSelection(false) },
|
package/dist/index.d.cts
CHANGED
|
@@ -193,8 +193,18 @@ declare class CompletionContext {
|
|
|
193
193
|
Allows you to register abort handlers, which will be called when
|
|
194
194
|
the query is
|
|
195
195
|
[aborted](https://codemirror.net/6/docs/ref/#autocomplete.CompletionContext.aborted).
|
|
196
|
-
|
|
197
|
-
|
|
196
|
+
|
|
197
|
+
By default, running queries will not be aborted for regular
|
|
198
|
+
typing or backspacing, on the assumption that they are likely to
|
|
199
|
+
return a result with a
|
|
200
|
+
[`validFor`](https://codemirror.net/6/docs/ref/#autocomplete.CompletionResult.validFor) field that
|
|
201
|
+
allows the result to be used after all. Passing `onDocChange:
|
|
202
|
+
true` will cause this query to be aborted for any document
|
|
203
|
+
change.
|
|
204
|
+
*/
|
|
205
|
+
addEventListener(type: "abort", listener: () => void, options?: {
|
|
206
|
+
onDocChange: boolean;
|
|
207
|
+
}): void;
|
|
198
208
|
}
|
|
199
209
|
/**
|
|
200
210
|
Given a a fixed array of options, return an autocompleter that
|
|
@@ -591,7 +601,7 @@ declare function autocompletion(config?: CompletionConfig): Extension;
|
|
|
591
601
|
/**
|
|
592
602
|
Basic keybindings for autocompletion.
|
|
593
603
|
|
|
594
|
-
- Ctrl-Space: [`startCompletion`](https://codemirror.net/6/docs/ref/#autocomplete.startCompletion)
|
|
604
|
+
- Ctrl-Space (and Alt-\` on macOS): [`startCompletion`](https://codemirror.net/6/docs/ref/#autocomplete.startCompletion)
|
|
595
605
|
- Escape: [`closeCompletion`](https://codemirror.net/6/docs/ref/#autocomplete.closeCompletion)
|
|
596
606
|
- ArrowDown: [`moveCompletionSelection`](https://codemirror.net/6/docs/ref/#autocomplete.moveCompletionSelection)`(true)`
|
|
597
607
|
- ArrowUp: [`moveCompletionSelection`](https://codemirror.net/6/docs/ref/#autocomplete.moveCompletionSelection)`(false)`
|
package/dist/index.d.ts
CHANGED
|
@@ -193,8 +193,18 @@ declare class CompletionContext {
|
|
|
193
193
|
Allows you to register abort handlers, which will be called when
|
|
194
194
|
the query is
|
|
195
195
|
[aborted](https://codemirror.net/6/docs/ref/#autocomplete.CompletionContext.aborted).
|
|
196
|
-
|
|
197
|
-
|
|
196
|
+
|
|
197
|
+
By default, running queries will not be aborted for regular
|
|
198
|
+
typing or backspacing, on the assumption that they are likely to
|
|
199
|
+
return a result with a
|
|
200
|
+
[`validFor`](https://codemirror.net/6/docs/ref/#autocomplete.CompletionResult.validFor) field that
|
|
201
|
+
allows the result to be used after all. Passing `onDocChange:
|
|
202
|
+
true` will cause this query to be aborted for any document
|
|
203
|
+
change.
|
|
204
|
+
*/
|
|
205
|
+
addEventListener(type: "abort", listener: () => void, options?: {
|
|
206
|
+
onDocChange: boolean;
|
|
207
|
+
}): void;
|
|
198
208
|
}
|
|
199
209
|
/**
|
|
200
210
|
Given a a fixed array of options, return an autocompleter that
|
|
@@ -591,7 +601,7 @@ declare function autocompletion(config?: CompletionConfig): Extension;
|
|
|
591
601
|
/**
|
|
592
602
|
Basic keybindings for autocompletion.
|
|
593
603
|
|
|
594
|
-
- Ctrl-Space: [`startCompletion`](https://codemirror.net/6/docs/ref/#autocomplete.startCompletion)
|
|
604
|
+
- Ctrl-Space (and Alt-\` on macOS): [`startCompletion`](https://codemirror.net/6/docs/ref/#autocomplete.startCompletion)
|
|
595
605
|
- Escape: [`closeCompletion`](https://codemirror.net/6/docs/ref/#autocomplete.closeCompletion)
|
|
596
606
|
- ArrowDown: [`moveCompletionSelection`](https://codemirror.net/6/docs/ref/#autocomplete.moveCompletionSelection)`(true)`
|
|
597
607
|
- ArrowUp: [`moveCompletionSelection`](https://codemirror.net/6/docs/ref/#autocomplete.moveCompletionSelection)`(false)`
|
package/dist/index.js
CHANGED
|
@@ -43,6 +43,10 @@ class CompletionContext {
|
|
|
43
43
|
@internal
|
|
44
44
|
*/
|
|
45
45
|
this.abortListeners = [];
|
|
46
|
+
/**
|
|
47
|
+
@internal
|
|
48
|
+
*/
|
|
49
|
+
this.abortOnDocChange = false;
|
|
46
50
|
}
|
|
47
51
|
/**
|
|
48
52
|
Get the extent, content, and (if there is a token) type of the
|
|
@@ -76,10 +80,21 @@ class CompletionContext {
|
|
|
76
80
|
Allows you to register abort handlers, which will be called when
|
|
77
81
|
the query is
|
|
78
82
|
[aborted](https://codemirror.net/6/docs/ref/#autocomplete.CompletionContext.aborted).
|
|
83
|
+
|
|
84
|
+
By default, running queries will not be aborted for regular
|
|
85
|
+
typing or backspacing, on the assumption that they are likely to
|
|
86
|
+
return a result with a
|
|
87
|
+
[`validFor`](https://codemirror.net/6/docs/ref/#autocomplete.CompletionResult.validFor) field that
|
|
88
|
+
allows the result to be used after all. Passing `onDocChange:
|
|
89
|
+
true` will cause this query to be aborted for any document
|
|
90
|
+
change.
|
|
79
91
|
*/
|
|
80
|
-
addEventListener(type, listener) {
|
|
81
|
-
if (type == "abort" && this.abortListeners)
|
|
92
|
+
addEventListener(type, listener, options) {
|
|
93
|
+
if (type == "abort" && this.abortListeners) {
|
|
82
94
|
this.abortListeners.push(listener);
|
|
95
|
+
if (options && options.onDocChange)
|
|
96
|
+
this.abortOnDocChange = true;
|
|
97
|
+
}
|
|
83
98
|
}
|
|
84
99
|
}
|
|
85
100
|
function toSet(chars) {
|
|
@@ -176,9 +191,10 @@ function insertCompletionText(state, text, from, to) {
|
|
|
176
191
|
if (range != main && from != to &&
|
|
177
192
|
state.sliceDoc(range.from + fromOff, range.from + toOff) != state.sliceDoc(from, to))
|
|
178
193
|
return { range };
|
|
194
|
+
let lines = state.toText(text);
|
|
179
195
|
return {
|
|
180
|
-
changes: { from: range.from + fromOff, to: to == main.from ? range.to : range.from + toOff, insert:
|
|
181
|
-
range: EditorSelection.cursor(range.from + fromOff +
|
|
196
|
+
changes: { from: range.from + fromOff, to: to == main.from ? range.to : range.from + toOff, insert: lines },
|
|
197
|
+
range: EditorSelection.cursor(range.from + fromOff + lines.length)
|
|
182
198
|
};
|
|
183
199
|
})), { scrollIntoView: true, userEvent: "input.complete" });
|
|
184
200
|
}
|
|
@@ -1100,6 +1116,7 @@ const completionPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
|
|
|
1100
1116
|
for (let i = 0; i < this.running.length; i++) {
|
|
1101
1117
|
let query = this.running[i];
|
|
1102
1118
|
if (doesReset ||
|
|
1119
|
+
query.context.abortOnDocChange && update.docChanged ||
|
|
1103
1120
|
query.updates.length + update.transactions.length > MaxUpdateCount && Date.now() - query.time > MinAbortTime) {
|
|
1104
1121
|
for (let handler of query.context.abortListeners) {
|
|
1105
1122
|
try {
|
|
@@ -1301,7 +1318,8 @@ const baseTheme = /*@__PURE__*/EditorView.baseTheme({
|
|
|
1301
1318
|
padding: "3px 9px",
|
|
1302
1319
|
width: "max-content",
|
|
1303
1320
|
maxWidth: `${400 /* Info.Width */}px`,
|
|
1304
|
-
boxSizing: "border-box"
|
|
1321
|
+
boxSizing: "border-box",
|
|
1322
|
+
whiteSpace: "pre-line"
|
|
1305
1323
|
},
|
|
1306
1324
|
".cm-completionInfo.cm-completionInfo-left": { right: "100%" },
|
|
1307
1325
|
".cm-completionInfo.cm-completionInfo-right": { left: "100%" },
|
|
@@ -1977,7 +1995,7 @@ function autocompletion(config = {}) {
|
|
|
1977
1995
|
/**
|
|
1978
1996
|
Basic keybindings for autocompletion.
|
|
1979
1997
|
|
|
1980
|
-
- Ctrl-Space: [`startCompletion`](https://codemirror.net/6/docs/ref/#autocomplete.startCompletion)
|
|
1998
|
+
- Ctrl-Space (and Alt-\` on macOS): [`startCompletion`](https://codemirror.net/6/docs/ref/#autocomplete.startCompletion)
|
|
1981
1999
|
- Escape: [`closeCompletion`](https://codemirror.net/6/docs/ref/#autocomplete.closeCompletion)
|
|
1982
2000
|
- ArrowDown: [`moveCompletionSelection`](https://codemirror.net/6/docs/ref/#autocomplete.moveCompletionSelection)`(true)`
|
|
1983
2001
|
- ArrowUp: [`moveCompletionSelection`](https://codemirror.net/6/docs/ref/#autocomplete.moveCompletionSelection)`(false)`
|
|
@@ -1987,6 +2005,7 @@ Basic keybindings for autocompletion.
|
|
|
1987
2005
|
*/
|
|
1988
2006
|
const completionKeymap = [
|
|
1989
2007
|
{ key: "Ctrl-Space", run: startCompletion },
|
|
2008
|
+
{ mac: "Alt-`", run: startCompletion },
|
|
1990
2009
|
{ key: "Escape", run: closeCompletion },
|
|
1991
2010
|
{ key: "ArrowDown", run: /*@__PURE__*/moveCompletionSelection(true) },
|
|
1992
2011
|
{ key: "ArrowUp", run: /*@__PURE__*/moveCompletionSelection(false) },
|