@codemirror/autocomplete 6.16.3 → 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,23 @@
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
+
11
+ ## 6.17.0 (2024-07-03)
12
+
13
+ ### Bug fixes
14
+
15
+ Fix an issue where completions weren't properly reset when starting a new completion through `activateOnCompletion`.
16
+
17
+ ### New features
18
+
19
+ `CompletionContext` objects now have a `view` property that holds the editor view when the query context has a view available.
20
+
1
21
  ## 6.16.3 (2024-06-19)
2
22
 
3
23
  ### Bug fixes
package/dist/index.cjs CHANGED
@@ -28,14 +28,27 @@ class CompletionContext {
28
28
  only return completions when either there is part of a
29
29
  completable entity before the cursor, or `explicit` is true.
30
30
  */
31
- explicit) {
31
+ explicit,
32
+ /**
33
+ The editor view. May be undefined if the context was created
34
+ in a situation where there is no such view available, such as
35
+ in synchronous updates via
36
+ [`CompletionResult.update`](https://codemirror.net/6/docs/ref/#autocomplete.CompletionResult.update)
37
+ or when called by test code.
38
+ */
39
+ view) {
32
40
  this.state = state;
33
41
  this.pos = pos;
34
42
  this.explicit = explicit;
43
+ this.view = view;
35
44
  /**
36
45
  @internal
37
46
  */
38
47
  this.abortListeners = [];
48
+ /**
49
+ @internal
50
+ */
51
+ this.abortOnDocChange = false;
39
52
  }
40
53
  /**
41
54
  Get the extent, content, and (if there is a token) type of the
@@ -69,10 +82,21 @@ class CompletionContext {
69
82
  Allows you to register abort handlers, which will be called when
70
83
  the query is
71
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.
72
93
  */
73
- addEventListener(type, listener) {
74
- if (type == "abort" && this.abortListeners)
94
+ addEventListener(type, listener, options) {
95
+ if (type == "abort" && this.abortListeners) {
75
96
  this.abortListeners.push(listener);
97
+ if (options && options.onDocChange)
98
+ this.abortOnDocChange = true;
99
+ }
76
100
  }
77
101
  }
78
102
  function toSet(chars) {
@@ -884,13 +908,18 @@ function makeAttrs(id, selected) {
884
908
  return result;
885
909
  }
886
910
  const none = [];
887
- function getUserEvent(tr, conf) {
911
+ function getUpdateType(tr, conf) {
888
912
  if (tr.isUserEvent("input.complete")) {
889
913
  let completion = tr.annotation(pickedCompletion);
890
914
  if (completion && conf.activateOnCompletion(completion))
891
- return "input";
915
+ return 4 /* UpdateType.Activate */ | 8 /* UpdateType.Reset */;
892
916
  }
893
- return tr.isUserEvent("input.type") ? "input" : tr.isUserEvent("delete.backward") ? "delete" : null;
917
+ let typing = tr.isUserEvent("input.type");
918
+ return typing && conf.activateOnTyping ? 4 /* UpdateType.Activate */ | 1 /* UpdateType.Typing */
919
+ : typing ? 1 /* UpdateType.Typing */
920
+ : tr.isUserEvent("delete.backward") ? 2 /* UpdateType.Backspacing */
921
+ : tr.selection ? 8 /* UpdateType.Reset */
922
+ : tr.docChanged ? 16 /* UpdateType.ResetIfTouching */ : 0 /* UpdateType.None */;
894
923
  }
895
924
  class ActiveSource {
896
925
  constructor(source, state, explicitPos = -1) {
@@ -900,13 +929,12 @@ class ActiveSource {
900
929
  }
901
930
  hasResult() { return false; }
902
931
  update(tr, conf) {
903
- let event = getUserEvent(tr, conf), value = this;
904
- if (event)
905
- value = value.handleUserEvent(tr, event, conf);
906
- else if (tr.docChanged)
907
- value = value.handleChange(tr);
908
- else if (tr.selection && value.state != 0 /* State.Inactive */)
932
+ let type = getUpdateType(tr, conf), value = this;
933
+ if ((type & 8 /* UpdateType.Reset */) || (type & 16 /* UpdateType.ResetIfTouching */) && this.touches(tr))
909
934
  value = new ActiveSource(value.source, 0 /* State.Inactive */);
935
+ if ((type & 4 /* UpdateType.Activate */) && value.state == 0 /* State.Inactive */)
936
+ value = new ActiveSource(this.source, 1 /* State.Pending */);
937
+ value = value.updateFor(tr, type);
910
938
  for (let effect of tr.effects) {
911
939
  if (effect.is(startCompletionEffect))
912
940
  value = new ActiveSource(value.source, 1 /* State.Pending */, effect.value ? cur(tr.state) : -1);
@@ -919,15 +947,13 @@ class ActiveSource {
919
947
  }
920
948
  return value;
921
949
  }
922
- handleUserEvent(tr, type, conf) {
923
- return type == "delete" || !conf.activateOnTyping ? this.map(tr.changes) : new ActiveSource(this.source, 1 /* State.Pending */);
924
- }
925
- handleChange(tr) {
926
- return tr.changes.touchesRange(cur(tr.startState)) ? new ActiveSource(this.source, 0 /* State.Inactive */) : this.map(tr.changes);
927
- }
950
+ updateFor(tr, type) { return this.map(tr.changes); }
928
951
  map(changes) {
929
952
  return changes.empty || this.explicitPos < 0 ? this : new ActiveSource(this.source, this.state, changes.mapPos(this.explicitPos));
930
953
  }
954
+ touches(tr) {
955
+ return tr.changes.touchesRange(cur(tr.state));
956
+ }
931
957
  }
932
958
  class ActiveResult extends ActiveSource {
933
959
  constructor(source, explicitPos, result, from, to) {
@@ -937,8 +963,10 @@ class ActiveResult extends ActiveSource {
937
963
  this.to = to;
938
964
  }
939
965
  hasResult() { return true; }
940
- handleUserEvent(tr, type, conf) {
966
+ updateFor(tr, type) {
941
967
  var _a;
968
+ if (!(type & 3 /* UpdateType.SimpleInteraction */))
969
+ return this.map(tr.changes);
942
970
  let result = this.result;
943
971
  if (result.map && !tr.changes.empty)
944
972
  result = result.map(result, tr.changes);
@@ -946,8 +974,8 @@ class ActiveResult extends ActiveSource {
946
974
  let pos = cur(tr.state);
947
975
  if ((this.explicitPos < 0 ? pos <= from : pos < this.from) ||
948
976
  pos > to || !result ||
949
- type == "delete" && cur(tr.startState) == this.from)
950
- return new ActiveSource(this.source, type == "input" && conf.activateOnTyping ? 1 /* State.Pending */ : 0 /* State.Inactive */);
977
+ (type & 2 /* UpdateType.Backspacing */) && cur(tr.startState) == this.from)
978
+ return new ActiveSource(this.source, type & 4 /* UpdateType.Activate */ ? 1 /* State.Pending */ : 0 /* State.Inactive */);
951
979
  let explicitPos = this.explicitPos < 0 ? -1 : tr.changes.mapPos(this.explicitPos);
952
980
  if (checkValid(result.validFor, tr.state, from, to))
953
981
  return new ActiveResult(this.source, explicitPos, result, from, to);
@@ -956,9 +984,6 @@ class ActiveResult extends ActiveSource {
956
984
  return new ActiveResult(this.source, explicitPos, result, result.from, (_a = result.to) !== null && _a !== void 0 ? _a : cur(tr.state));
957
985
  return new ActiveSource(this.source, 1 /* State.Pending */, explicitPos);
958
986
  }
959
- handleChange(tr) {
960
- return tr.changes.touchesRange(this.from, this.to) ? new ActiveSource(this.source, 0 /* State.Inactive */) : this.map(tr.changes);
961
- }
962
987
  map(mapping) {
963
988
  if (mapping.empty)
964
989
  return this;
@@ -967,6 +992,9 @@ class ActiveResult extends ActiveSource {
967
992
  return new ActiveSource(this.source, 0 /* State.Inactive */);
968
993
  return new ActiveResult(this.source, this.explicitPos < 0 ? -1 : mapping.mapPos(this.explicitPos), this.result, mapping.mapPos(this.from), mapping.mapPos(this.to, 1));
969
994
  }
995
+ touches(tr) {
996
+ return tr.changes.touchesRange(this.from, this.to);
997
+ }
970
998
  }
971
999
  function checkValid(validFor, state, from, to) {
972
1000
  if (!validFor)
@@ -1083,11 +1111,13 @@ const completionPlugin = view.ViewPlugin.fromClass(class {
1083
1111
  if (!update.selectionSet && !update.docChanged && update.startState.field(completionState) == cState)
1084
1112
  return;
1085
1113
  let doesReset = update.transactions.some(tr => {
1086
- return (tr.selection || tr.docChanged) && !getUserEvent(tr, conf);
1114
+ let type = getUpdateType(tr, conf);
1115
+ return (type & 8 /* UpdateType.Reset */) || (tr.selection || tr.docChanged) && !(type & 3 /* UpdateType.SimpleInteraction */);
1087
1116
  });
1088
1117
  for (let i = 0; i < this.running.length; i++) {
1089
1118
  let query = this.running[i];
1090
1119
  if (doesReset ||
1120
+ query.context.abortOnDocChange && update.docChanged ||
1091
1121
  query.updates.length + update.transactions.length > MaxUpdateCount && Date.now() - query.time > MinAbortTime) {
1092
1122
  for (let handler of query.context.abortListeners) {
1093
1123
  try {
@@ -1113,7 +1143,7 @@ const completionPlugin = view.ViewPlugin.fromClass(class {
1113
1143
  ? setTimeout(() => this.startUpdate(), delay) : -1;
1114
1144
  if (this.composing != 0 /* CompositionState.None */)
1115
1145
  for (let tr of update.transactions) {
1116
- if (getUserEvent(tr, conf) == "input")
1146
+ if (tr.isUserEvent("input.type"))
1117
1147
  this.composing = 2 /* CompositionState.Changed */;
1118
1148
  else if (this.composing == 2 /* CompositionState.Changed */ && tr.selection)
1119
1149
  this.composing = 3 /* CompositionState.ChangedAndMoved */;
@@ -1130,7 +1160,7 @@ const completionPlugin = view.ViewPlugin.fromClass(class {
1130
1160
  }
1131
1161
  startQuery(active) {
1132
1162
  let { state } = this.view, pos = cur(state);
1133
- let context = new CompletionContext(state, pos, active.explicitPos == pos);
1163
+ let context = new CompletionContext(state, pos, active.explicitPos == pos, this.view);
1134
1164
  let pending = new RunningQuery(active, context);
1135
1165
  this.running.push(pending);
1136
1166
  Promise.resolve(active.source(context)).then(result => {
@@ -1289,7 +1319,8 @@ const baseTheme = view.EditorView.baseTheme({
1289
1319
  padding: "3px 9px",
1290
1320
  width: "max-content",
1291
1321
  maxWidth: `${400 /* Info.Width */}px`,
1292
- boxSizing: "border-box"
1322
+ boxSizing: "border-box",
1323
+ whiteSpace: "pre-line"
1293
1324
  },
1294
1325
  ".cm-completionInfo.cm-completionInfo-left": { right: "100%" },
1295
1326
  ".cm-completionInfo.cm-completionInfo-right": { left: "100%" },
package/dist/index.d.cts CHANGED
@@ -129,6 +129,14 @@ declare class CompletionContext {
129
129
  */
130
130
  readonly explicit: boolean;
131
131
  /**
132
+ The editor view. May be undefined if the context was created
133
+ in a situation where there is no such view available, such as
134
+ in synchronous updates via
135
+ [`CompletionResult.update`](https://codemirror.net/6/docs/ref/#autocomplete.CompletionResult.update)
136
+ or when called by test code.
137
+ */
138
+ readonly view?: EditorView | undefined;
139
+ /**
132
140
  Create a new completion context. (Mostly useful for testing
133
141
  completion sources—in the editor, the extension will create
134
142
  these for you.)
@@ -148,7 +156,15 @@ declare class CompletionContext {
148
156
  only return completions when either there is part of a
149
157
  completable entity before the cursor, or `explicit` is true.
150
158
  */
151
- explicit: boolean);
159
+ explicit: boolean,
160
+ /**
161
+ The editor view. May be undefined if the context was created
162
+ in a situation where there is no such view available, such as
163
+ in synchronous updates via
164
+ [`CompletionResult.update`](https://codemirror.net/6/docs/ref/#autocomplete.CompletionResult.update)
165
+ or when called by test code.
166
+ */
167
+ view?: EditorView | undefined);
152
168
  /**
153
169
  Get the extent, content, and (if there is a token) type of the
154
170
  token before `this.pos`.
@@ -177,8 +193,18 @@ declare class CompletionContext {
177
193
  Allows you to register abort handlers, which will be called when
178
194
  the query is
179
195
  [aborted](https://codemirror.net/6/docs/ref/#autocomplete.CompletionContext.aborted).
180
- */
181
- 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;
182
208
  }
183
209
  /**
184
210
  Given a a fixed array of options, return an autocompleter that
package/dist/index.d.ts CHANGED
@@ -129,6 +129,14 @@ declare class CompletionContext {
129
129
  */
130
130
  readonly explicit: boolean;
131
131
  /**
132
+ The editor view. May be undefined if the context was created
133
+ in a situation where there is no such view available, such as
134
+ in synchronous updates via
135
+ [`CompletionResult.update`](https://codemirror.net/6/docs/ref/#autocomplete.CompletionResult.update)
136
+ or when called by test code.
137
+ */
138
+ readonly view?: EditorView | undefined;
139
+ /**
132
140
  Create a new completion context. (Mostly useful for testing
133
141
  completion sources—in the editor, the extension will create
134
142
  these for you.)
@@ -148,7 +156,15 @@ declare class CompletionContext {
148
156
  only return completions when either there is part of a
149
157
  completable entity before the cursor, or `explicit` is true.
150
158
  */
151
- explicit: boolean);
159
+ explicit: boolean,
160
+ /**
161
+ The editor view. May be undefined if the context was created
162
+ in a situation where there is no such view available, such as
163
+ in synchronous updates via
164
+ [`CompletionResult.update`](https://codemirror.net/6/docs/ref/#autocomplete.CompletionResult.update)
165
+ or when called by test code.
166
+ */
167
+ view?: EditorView | undefined);
152
168
  /**
153
169
  Get the extent, content, and (if there is a token) type of the
154
170
  token before `this.pos`.
@@ -177,8 +193,18 @@ declare class CompletionContext {
177
193
  Allows you to register abort handlers, which will be called when
178
194
  the query is
179
195
  [aborted](https://codemirror.net/6/docs/ref/#autocomplete.CompletionContext.aborted).
180
- */
181
- 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;
182
208
  }
183
209
  /**
184
210
  Given a a fixed array of options, return an autocompleter that
package/dist/index.js CHANGED
@@ -26,14 +26,27 @@ class CompletionContext {
26
26
  only return completions when either there is part of a
27
27
  completable entity before the cursor, or `explicit` is true.
28
28
  */
29
- explicit) {
29
+ explicit,
30
+ /**
31
+ The editor view. May be undefined if the context was created
32
+ in a situation where there is no such view available, such as
33
+ in synchronous updates via
34
+ [`CompletionResult.update`](https://codemirror.net/6/docs/ref/#autocomplete.CompletionResult.update)
35
+ or when called by test code.
36
+ */
37
+ view) {
30
38
  this.state = state;
31
39
  this.pos = pos;
32
40
  this.explicit = explicit;
41
+ this.view = view;
33
42
  /**
34
43
  @internal
35
44
  */
36
45
  this.abortListeners = [];
46
+ /**
47
+ @internal
48
+ */
49
+ this.abortOnDocChange = false;
37
50
  }
38
51
  /**
39
52
  Get the extent, content, and (if there is a token) type of the
@@ -67,10 +80,21 @@ class CompletionContext {
67
80
  Allows you to register abort handlers, which will be called when
68
81
  the query is
69
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.
70
91
  */
71
- addEventListener(type, listener) {
72
- if (type == "abort" && this.abortListeners)
92
+ addEventListener(type, listener, options) {
93
+ if (type == "abort" && this.abortListeners) {
73
94
  this.abortListeners.push(listener);
95
+ if (options && options.onDocChange)
96
+ this.abortOnDocChange = true;
97
+ }
74
98
  }
75
99
  }
76
100
  function toSet(chars) {
@@ -882,13 +906,18 @@ function makeAttrs(id, selected) {
882
906
  return result;
883
907
  }
884
908
  const none = [];
885
- function getUserEvent(tr, conf) {
909
+ function getUpdateType(tr, conf) {
886
910
  if (tr.isUserEvent("input.complete")) {
887
911
  let completion = tr.annotation(pickedCompletion);
888
912
  if (completion && conf.activateOnCompletion(completion))
889
- return "input";
913
+ return 4 /* UpdateType.Activate */ | 8 /* UpdateType.Reset */;
890
914
  }
891
- return tr.isUserEvent("input.type") ? "input" : tr.isUserEvent("delete.backward") ? "delete" : null;
915
+ let typing = tr.isUserEvent("input.type");
916
+ return typing && conf.activateOnTyping ? 4 /* UpdateType.Activate */ | 1 /* UpdateType.Typing */
917
+ : typing ? 1 /* UpdateType.Typing */
918
+ : tr.isUserEvent("delete.backward") ? 2 /* UpdateType.Backspacing */
919
+ : tr.selection ? 8 /* UpdateType.Reset */
920
+ : tr.docChanged ? 16 /* UpdateType.ResetIfTouching */ : 0 /* UpdateType.None */;
892
921
  }
893
922
  class ActiveSource {
894
923
  constructor(source, state, explicitPos = -1) {
@@ -898,13 +927,12 @@ class ActiveSource {
898
927
  }
899
928
  hasResult() { return false; }
900
929
  update(tr, conf) {
901
- let event = getUserEvent(tr, conf), value = this;
902
- if (event)
903
- value = value.handleUserEvent(tr, event, conf);
904
- else if (tr.docChanged)
905
- value = value.handleChange(tr);
906
- else if (tr.selection && value.state != 0 /* State.Inactive */)
930
+ let type = getUpdateType(tr, conf), value = this;
931
+ if ((type & 8 /* UpdateType.Reset */) || (type & 16 /* UpdateType.ResetIfTouching */) && this.touches(tr))
907
932
  value = new ActiveSource(value.source, 0 /* State.Inactive */);
933
+ if ((type & 4 /* UpdateType.Activate */) && value.state == 0 /* State.Inactive */)
934
+ value = new ActiveSource(this.source, 1 /* State.Pending */);
935
+ value = value.updateFor(tr, type);
908
936
  for (let effect of tr.effects) {
909
937
  if (effect.is(startCompletionEffect))
910
938
  value = new ActiveSource(value.source, 1 /* State.Pending */, effect.value ? cur(tr.state) : -1);
@@ -917,15 +945,13 @@ class ActiveSource {
917
945
  }
918
946
  return value;
919
947
  }
920
- handleUserEvent(tr, type, conf) {
921
- return type == "delete" || !conf.activateOnTyping ? this.map(tr.changes) : new ActiveSource(this.source, 1 /* State.Pending */);
922
- }
923
- handleChange(tr) {
924
- return tr.changes.touchesRange(cur(tr.startState)) ? new ActiveSource(this.source, 0 /* State.Inactive */) : this.map(tr.changes);
925
- }
948
+ updateFor(tr, type) { return this.map(tr.changes); }
926
949
  map(changes) {
927
950
  return changes.empty || this.explicitPos < 0 ? this : new ActiveSource(this.source, this.state, changes.mapPos(this.explicitPos));
928
951
  }
952
+ touches(tr) {
953
+ return tr.changes.touchesRange(cur(tr.state));
954
+ }
929
955
  }
930
956
  class ActiveResult extends ActiveSource {
931
957
  constructor(source, explicitPos, result, from, to) {
@@ -935,8 +961,10 @@ class ActiveResult extends ActiveSource {
935
961
  this.to = to;
936
962
  }
937
963
  hasResult() { return true; }
938
- handleUserEvent(tr, type, conf) {
964
+ updateFor(tr, type) {
939
965
  var _a;
966
+ if (!(type & 3 /* UpdateType.SimpleInteraction */))
967
+ return this.map(tr.changes);
940
968
  let result = this.result;
941
969
  if (result.map && !tr.changes.empty)
942
970
  result = result.map(result, tr.changes);
@@ -944,8 +972,8 @@ class ActiveResult extends ActiveSource {
944
972
  let pos = cur(tr.state);
945
973
  if ((this.explicitPos < 0 ? pos <= from : pos < this.from) ||
946
974
  pos > to || !result ||
947
- type == "delete" && cur(tr.startState) == this.from)
948
- return new ActiveSource(this.source, type == "input" && conf.activateOnTyping ? 1 /* State.Pending */ : 0 /* State.Inactive */);
975
+ (type & 2 /* UpdateType.Backspacing */) && cur(tr.startState) == this.from)
976
+ return new ActiveSource(this.source, type & 4 /* UpdateType.Activate */ ? 1 /* State.Pending */ : 0 /* State.Inactive */);
949
977
  let explicitPos = this.explicitPos < 0 ? -1 : tr.changes.mapPos(this.explicitPos);
950
978
  if (checkValid(result.validFor, tr.state, from, to))
951
979
  return new ActiveResult(this.source, explicitPos, result, from, to);
@@ -954,9 +982,6 @@ class ActiveResult extends ActiveSource {
954
982
  return new ActiveResult(this.source, explicitPos, result, result.from, (_a = result.to) !== null && _a !== void 0 ? _a : cur(tr.state));
955
983
  return new ActiveSource(this.source, 1 /* State.Pending */, explicitPos);
956
984
  }
957
- handleChange(tr) {
958
- return tr.changes.touchesRange(this.from, this.to) ? new ActiveSource(this.source, 0 /* State.Inactive */) : this.map(tr.changes);
959
- }
960
985
  map(mapping) {
961
986
  if (mapping.empty)
962
987
  return this;
@@ -965,6 +990,9 @@ class ActiveResult extends ActiveSource {
965
990
  return new ActiveSource(this.source, 0 /* State.Inactive */);
966
991
  return new ActiveResult(this.source, this.explicitPos < 0 ? -1 : mapping.mapPos(this.explicitPos), this.result, mapping.mapPos(this.from), mapping.mapPos(this.to, 1));
967
992
  }
993
+ touches(tr) {
994
+ return tr.changes.touchesRange(this.from, this.to);
995
+ }
968
996
  }
969
997
  function checkValid(validFor, state, from, to) {
970
998
  if (!validFor)
@@ -1081,11 +1109,13 @@ const completionPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
1081
1109
  if (!update.selectionSet && !update.docChanged && update.startState.field(completionState) == cState)
1082
1110
  return;
1083
1111
  let doesReset = update.transactions.some(tr => {
1084
- return (tr.selection || tr.docChanged) && !getUserEvent(tr, conf);
1112
+ let type = getUpdateType(tr, conf);
1113
+ return (type & 8 /* UpdateType.Reset */) || (tr.selection || tr.docChanged) && !(type & 3 /* UpdateType.SimpleInteraction */);
1085
1114
  });
1086
1115
  for (let i = 0; i < this.running.length; i++) {
1087
1116
  let query = this.running[i];
1088
1117
  if (doesReset ||
1118
+ query.context.abortOnDocChange && update.docChanged ||
1089
1119
  query.updates.length + update.transactions.length > MaxUpdateCount && Date.now() - query.time > MinAbortTime) {
1090
1120
  for (let handler of query.context.abortListeners) {
1091
1121
  try {
@@ -1111,7 +1141,7 @@ const completionPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
1111
1141
  ? setTimeout(() => this.startUpdate(), delay) : -1;
1112
1142
  if (this.composing != 0 /* CompositionState.None */)
1113
1143
  for (let tr of update.transactions) {
1114
- if (getUserEvent(tr, conf) == "input")
1144
+ if (tr.isUserEvent("input.type"))
1115
1145
  this.composing = 2 /* CompositionState.Changed */;
1116
1146
  else if (this.composing == 2 /* CompositionState.Changed */ && tr.selection)
1117
1147
  this.composing = 3 /* CompositionState.ChangedAndMoved */;
@@ -1128,7 +1158,7 @@ const completionPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
1128
1158
  }
1129
1159
  startQuery(active) {
1130
1160
  let { state } = this.view, pos = cur(state);
1131
- let context = new CompletionContext(state, pos, active.explicitPos == pos);
1161
+ let context = new CompletionContext(state, pos, active.explicitPos == pos, this.view);
1132
1162
  let pending = new RunningQuery(active, context);
1133
1163
  this.running.push(pending);
1134
1164
  Promise.resolve(active.source(context)).then(result => {
@@ -1287,7 +1317,8 @@ const baseTheme = /*@__PURE__*/EditorView.baseTheme({
1287
1317
  padding: "3px 9px",
1288
1318
  width: "max-content",
1289
1319
  maxWidth: `${400 /* Info.Width */}px`,
1290
- boxSizing: "border-box"
1320
+ boxSizing: "border-box",
1321
+ whiteSpace: "pre-line"
1291
1322
  },
1292
1323
  ".cm-completionInfo.cm-completionInfo-left": { right: "100%" },
1293
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.16.3",
3
+ "version": "6.18.0",
4
4
  "description": "Autocompletion for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",