@codemirror/autocomplete 6.17.0 → 6.18.0

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,13 @@
1
+ ## 6.18.0 (2024-08-05)
2
+
3
+ ### Bug fixes
4
+
5
+ Style the info element so that newlines are preserved, to make it easier to display multi-line info from a string source.
6
+
7
+ ### New features
8
+
9
+ 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.
10
+
1
11
  ## 6.17.0 (2024-07-03)
2
12
 
3
13
  ### 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) {
@@ -1102,6 +1117,7 @@ const completionPlugin = view.ViewPlugin.fromClass(class {
1102
1117
  for (let i = 0; i < this.running.length; i++) {
1103
1118
  let query = this.running[i];
1104
1119
  if (doesReset ||
1120
+ query.context.abortOnDocChange && update.docChanged ||
1105
1121
  query.updates.length + update.transactions.length > MaxUpdateCount && Date.now() - query.time > MinAbortTime) {
1106
1122
  for (let handler of query.context.abortListeners) {
1107
1123
  try {
@@ -1303,7 +1319,8 @@ const baseTheme = view.EditorView.baseTheme({
1303
1319
  padding: "3px 9px",
1304
1320
  width: "max-content",
1305
1321
  maxWidth: `${400 /* Info.Width */}px`,
1306
- boxSizing: "border-box"
1322
+ boxSizing: "border-box",
1323
+ whiteSpace: "pre-line"
1307
1324
  },
1308
1325
  ".cm-completionInfo.cm-completionInfo-left": { right: "100%" },
1309
1326
  ".cm-completionInfo.cm-completionInfo-right": { left: "100%" },
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
- addEventListener(type: "abort", listener: () => void): void;
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
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
- addEventListener(type: "abort", listener: () => void): void;
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
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) {
@@ -1100,6 +1115,7 @@ const completionPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
1100
1115
  for (let i = 0; i < this.running.length; i++) {
1101
1116
  let query = this.running[i];
1102
1117
  if (doesReset ||
1118
+ query.context.abortOnDocChange && update.docChanged ||
1103
1119
  query.updates.length + update.transactions.length > MaxUpdateCount && Date.now() - query.time > MinAbortTime) {
1104
1120
  for (let handler of query.context.abortListeners) {
1105
1121
  try {
@@ -1301,7 +1317,8 @@ const baseTheme = /*@__PURE__*/EditorView.baseTheme({
1301
1317
  padding: "3px 9px",
1302
1318
  width: "max-content",
1303
1319
  maxWidth: `${400 /* Info.Width */}px`,
1304
- boxSizing: "border-box"
1320
+ boxSizing: "border-box",
1321
+ whiteSpace: "pre-line"
1305
1322
  },
1306
1323
  ".cm-completionInfo.cm-completionInfo-left": { right: "100%" },
1307
1324
  ".cm-completionInfo.cm-completionInfo-right": { left: "100%" },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemirror/autocomplete",
3
- "version": "6.17.0",
3
+ "version": "6.18.0",
4
4
  "description": "Autocompletion for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",