@codemirror/autocomplete 6.18.1 → 6.18.3

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,15 @@
1
+ ## 6.18.3 (2024-11-13)
2
+
3
+ ### Bug fixes
4
+
5
+ Backspacing to the start of the completed range will no longer close the completion tooltip when it was triggered implicitly by typing the character before that range.
6
+
7
+ ## 6.18.2 (2024-10-30)
8
+
9
+ ### Bug fixes
10
+
11
+ Don't immediately show synchronously updated completions when there are some sources that still need to return.
12
+
1
13
  ## 6.18.1 (2024-09-14)
2
14
 
3
15
  ### Bug fixes
package/dist/index.cjs CHANGED
@@ -816,12 +816,12 @@ class CompletionDialog {
816
816
  return selected == this.selected || selected >= this.options.length ? this
817
817
  : new CompletionDialog(this.options, makeAttrs(id, selected), this.tooltip, this.timestamp, selected, this.disabled);
818
818
  }
819
- static build(active, state, id, prev, conf) {
819
+ static build(active, state, id, prev, conf, didSetActive) {
820
+ if (prev && !didSetActive && active.some(s => s.isPending))
821
+ return prev.setDisabled();
820
822
  let options = sortOptions(active, state);
821
- if (!options.length) {
822
- return prev && active.some(a => a.state == 1 /* State.Pending */) ?
823
- new CompletionDialog(prev.options, prev.attrs, prev.tooltip, prev.timestamp, prev.selected, true) : null;
824
- }
823
+ if (!options.length)
824
+ return prev && active.some(a => a.isPending) ? prev.setDisabled() : null;
825
825
  let selected = state.facet(completionConfig).selectOnOpen ? 0 : -1;
826
826
  if (prev && prev.selected != selected && prev.selected != -1) {
827
827
  let selectedValue = prev.options[prev.selected].completion;
@@ -840,6 +840,9 @@ class CompletionDialog {
840
840
  map(changes) {
841
841
  return new CompletionDialog(this.options, this.attrs, Object.assign(Object.assign({}, this.tooltip), { pos: changes.mapPos(this.tooltip.pos) }), this.timestamp, this.selected, this.disabled);
842
842
  }
843
+ setDisabled() {
844
+ return new CompletionDialog(this.options, this.attrs, this.tooltip, this.timestamp, this.selected, true);
845
+ }
843
846
  }
844
847
  class CompletionState {
845
848
  constructor(active, id, open) {
@@ -861,15 +864,15 @@ class CompletionState {
861
864
  });
862
865
  if (active.length == this.active.length && active.every((a, i) => a == this.active[i]))
863
866
  active = this.active;
864
- let open = this.open;
867
+ let open = this.open, didSet = tr.effects.some(e => e.is(setActiveEffect));
865
868
  if (open && tr.docChanged)
866
869
  open = open.map(tr.changes);
867
870
  if (tr.selection || active.some(a => a.hasResult() && tr.changes.touchesRange(a.from, a.to)) ||
868
- !sameResults(active, this.active))
869
- open = CompletionDialog.build(active, state, this.id, open, conf);
870
- else if (open && open.disabled && !active.some(a => a.state == 1 /* State.Pending */))
871
+ !sameResults(active, this.active) || didSet)
872
+ open = CompletionDialog.build(active, state, this.id, open, conf, didSet);
873
+ else if (open && open.disabled && !active.some(a => a.isPending))
871
874
  open = null;
872
- if (!open && active.every(a => a.state != 1 /* State.Pending */) && active.some(a => a.hasResult()))
875
+ if (!open && active.every(a => !a.isPending) && active.some(a => a.hasResult()))
873
876
  active = active.map(a => a.hasResult() ? new ActiveSource(a.source, 0 /* State.Inactive */) : a);
874
877
  for (let effect of tr.effects)
875
878
  if (effect.is(setSelectedEffect))
@@ -883,9 +886,9 @@ function sameResults(a, b) {
883
886
  if (a == b)
884
887
  return true;
885
888
  for (let iA = 0, iB = 0;;) {
886
- while (iA < a.length && !a[iA].hasResult)
889
+ while (iA < a.length && !a[iA].hasResult())
887
890
  iA++;
888
- while (iB < b.length && !b[iB].hasResult)
891
+ while (iB < b.length && !b[iB].hasResult())
889
892
  iB++;
890
893
  let endA = iA == a.length, endB = iB == b.length;
891
894
  if (endA || endB)
@@ -923,12 +926,13 @@ function getUpdateType(tr, conf) {
923
926
  : tr.docChanged ? 16 /* UpdateType.ResetIfTouching */ : 0 /* UpdateType.None */;
924
927
  }
925
928
  class ActiveSource {
926
- constructor(source, state, explicitPos = -1) {
929
+ constructor(source, state, explicit = false) {
927
930
  this.source = source;
928
931
  this.state = state;
929
- this.explicitPos = explicitPos;
932
+ this.explicit = explicit;
930
933
  }
931
934
  hasResult() { return false; }
935
+ get isPending() { return this.state == 1 /* State.Pending */; }
932
936
  update(tr, conf) {
933
937
  let type = getUpdateType(tr, conf), value = this;
934
938
  if ((type & 8 /* UpdateType.Reset */) || (type & 16 /* UpdateType.ResetIfTouching */) && this.touches(tr))
@@ -938,7 +942,7 @@ class ActiveSource {
938
942
  value = value.updateFor(tr, type);
939
943
  for (let effect of tr.effects) {
940
944
  if (effect.is(startCompletionEffect))
941
- value = new ActiveSource(value.source, 1 /* State.Pending */, effect.value ? cur(tr.state) : -1);
945
+ value = new ActiveSource(value.source, 1 /* State.Pending */, effect.value);
942
946
  else if (effect.is(closeCompletionEffect))
943
947
  value = new ActiveSource(value.source, 0 /* State.Inactive */);
944
948
  else if (effect.is(setActiveEffect))
@@ -949,16 +953,15 @@ class ActiveSource {
949
953
  return value;
950
954
  }
951
955
  updateFor(tr, type) { return this.map(tr.changes); }
952
- map(changes) {
953
- return changes.empty || this.explicitPos < 0 ? this : new ActiveSource(this.source, this.state, changes.mapPos(this.explicitPos));
954
- }
956
+ map(changes) { return this; }
955
957
  touches(tr) {
956
958
  return tr.changes.touchesRange(cur(tr.state));
957
959
  }
958
960
  }
959
961
  class ActiveResult extends ActiveSource {
960
- constructor(source, explicitPos, result, from, to) {
961
- super(source, 2 /* State.Result */, explicitPos);
962
+ constructor(source, explicit, limit, result, from, to) {
963
+ super(source, 3 /* State.Result */, explicit);
964
+ this.limit = limit;
962
965
  this.result = result;
963
966
  this.from = from;
964
967
  this.to = to;
@@ -973,17 +976,16 @@ class ActiveResult extends ActiveSource {
973
976
  result = result.map(result, tr.changes);
974
977
  let from = tr.changes.mapPos(this.from), to = tr.changes.mapPos(this.to, 1);
975
978
  let pos = cur(tr.state);
976
- if ((this.explicitPos < 0 ? pos <= from : pos < this.from) ||
977
- pos > to || !result ||
978
- (type & 2 /* UpdateType.Backspacing */) && cur(tr.startState) == this.from)
979
+ if (pos > to || !result ||
980
+ (type & 2 /* UpdateType.Backspacing */) && (cur(tr.startState) == this.from || pos < this.limit))
979
981
  return new ActiveSource(this.source, type & 4 /* UpdateType.Activate */ ? 1 /* State.Pending */ : 0 /* State.Inactive */);
980
- let explicitPos = this.explicitPos < 0 ? -1 : tr.changes.mapPos(this.explicitPos);
982
+ let limit = tr.changes.mapPos(this.limit);
981
983
  if (checkValid(result.validFor, tr.state, from, to))
982
- return new ActiveResult(this.source, explicitPos, result, from, to);
984
+ return new ActiveResult(this.source, this.explicit, limit, result, from, to);
983
985
  if (result.update &&
984
- (result = result.update(result, from, to, new CompletionContext(tr.state, pos, explicitPos >= 0))))
985
- return new ActiveResult(this.source, explicitPos, result, result.from, (_a = result.to) !== null && _a !== void 0 ? _a : cur(tr.state));
986
- return new ActiveSource(this.source, 1 /* State.Pending */, explicitPos);
986
+ (result = result.update(result, from, to, new CompletionContext(tr.state, pos, false))))
987
+ return new ActiveResult(this.source, this.explicit, limit, result, result.from, (_a = result.to) !== null && _a !== void 0 ? _a : cur(tr.state));
988
+ return new ActiveSource(this.source, 1 /* State.Pending */, this.explicit);
987
989
  }
988
990
  map(mapping) {
989
991
  if (mapping.empty)
@@ -991,7 +993,7 @@ class ActiveResult extends ActiveSource {
991
993
  let result = this.result.map ? this.result.map(this.result, mapping) : this.result;
992
994
  if (!result)
993
995
  return new ActiveSource(this.source, 0 /* State.Inactive */);
994
- return new ActiveResult(this.source, this.explicitPos < 0 ? -1 : mapping.mapPos(this.explicitPos), this.result, mapping.mapPos(this.from), mapping.mapPos(this.to, 1));
996
+ return new ActiveResult(this.source, this.explicit, mapping.mapPos(this.limit), this.result, mapping.mapPos(this.from), mapping.mapPos(this.to, 1));
995
997
  }
996
998
  touches(tr) {
997
999
  return tr.changes.touchesRange(this.from, this.to);
@@ -1103,7 +1105,7 @@ const completionPlugin = view.ViewPlugin.fromClass(class {
1103
1105
  this.pendingStart = false;
1104
1106
  this.composing = 0 /* CompositionState.None */;
1105
1107
  for (let active of view.state.field(completionState).active)
1106
- if (active.state == 1 /* State.Pending */)
1108
+ if (active.isPending)
1107
1109
  this.startQuery(active);
1108
1110
  }
1109
1111
  update(update) {
@@ -1140,7 +1142,7 @@ const completionPlugin = view.ViewPlugin.fromClass(class {
1140
1142
  if (update.transactions.some(tr => tr.effects.some(e => e.is(startCompletionEffect))))
1141
1143
  this.pendingStart = true;
1142
1144
  let delay = this.pendingStart ? 50 : conf.activateOnTypingDelay;
1143
- this.debounceUpdate = cState.active.some(a => a.state == 1 /* State.Pending */ && !this.running.some(q => q.active.source == a.source))
1145
+ this.debounceUpdate = cState.active.some(a => a.isPending && !this.running.some(q => q.active.source == a.source))
1144
1146
  ? setTimeout(() => this.startUpdate(), delay) : -1;
1145
1147
  if (this.composing != 0 /* CompositionState.None */)
1146
1148
  for (let tr of update.transactions) {
@@ -1155,13 +1157,15 @@ const completionPlugin = view.ViewPlugin.fromClass(class {
1155
1157
  this.pendingStart = false;
1156
1158
  let { state } = this.view, cState = state.field(completionState);
1157
1159
  for (let active of cState.active) {
1158
- if (active.state == 1 /* State.Pending */ && !this.running.some(r => r.active.source == active.source))
1160
+ if (active.isPending && !this.running.some(r => r.active.source == active.source))
1159
1161
  this.startQuery(active);
1160
1162
  }
1163
+ if (this.running.length && cState.open && cState.open.disabled)
1164
+ this.debounceAccept = setTimeout(() => this.accept(), this.view.state.facet(completionConfig).updateSyncTime);
1161
1165
  }
1162
1166
  startQuery(active) {
1163
1167
  let { state } = this.view, pos = cur(state);
1164
- let context = new CompletionContext(state, pos, active.explicitPos == pos, this.view);
1168
+ let context = new CompletionContext(state, pos, active.explicit, this.view);
1165
1169
  let pending = new RunningQuery(active, context);
1166
1170
  this.running.push(pending);
1167
1171
  Promise.resolve(active.source(context)).then(result => {
@@ -1188,14 +1192,16 @@ const completionPlugin = view.ViewPlugin.fromClass(class {
1188
1192
  clearTimeout(this.debounceAccept);
1189
1193
  this.debounceAccept = -1;
1190
1194
  let updated = [];
1191
- let conf = this.view.state.facet(completionConfig);
1195
+ let conf = this.view.state.facet(completionConfig), cState = this.view.state.field(completionState);
1192
1196
  for (let i = 0; i < this.running.length; i++) {
1193
1197
  let query = this.running[i];
1194
1198
  if (query.done === undefined)
1195
1199
  continue;
1196
1200
  this.running.splice(i--, 1);
1197
1201
  if (query.done) {
1198
- let active = new ActiveResult(query.active.source, query.active.explicitPos, query.done, query.done.from, (_a = query.done.to) !== null && _a !== void 0 ? _a : cur(query.updates.length ? query.updates[0].startState : this.view.state));
1202
+ let pos = cur(query.updates.length ? query.updates[0].startState : this.view.state);
1203
+ let limit = Math.min(pos, query.done.from + (query.active.explicit ? 0 : 1));
1204
+ let active = new ActiveResult(query.active.source, query.active.explicit, limit, query.done, query.done.from, (_a = query.done.to) !== null && _a !== void 0 ? _a : pos);
1199
1205
  // Replay the transactions that happened since the start of
1200
1206
  // the request and see if that preserves the result
1201
1207
  for (let tr of query.updates)
@@ -1205,15 +1211,15 @@ const completionPlugin = view.ViewPlugin.fromClass(class {
1205
1211
  continue;
1206
1212
  }
1207
1213
  }
1208
- let current = this.view.state.field(completionState).active.find(a => a.source == query.active.source);
1209
- if (current && current.state == 1 /* State.Pending */) {
1214
+ let current = cState.active.find(a => a.source == query.active.source);
1215
+ if (current && current.isPending) {
1210
1216
  if (query.done == null) {
1211
1217
  // Explicitly failed. Should clear the pending status if it
1212
1218
  // hasn't been re-set in the meantime.
1213
1219
  let active = new ActiveSource(query.active.source, 0 /* State.Inactive */);
1214
1220
  for (let tr of query.updates)
1215
1221
  active = active.update(tr, conf);
1216
- if (active.state != 1 /* State.Pending */)
1222
+ if (!active.isPending)
1217
1223
  updated.push(active);
1218
1224
  }
1219
1225
  else {
@@ -1222,7 +1228,7 @@ const completionPlugin = view.ViewPlugin.fromClass(class {
1222
1228
  }
1223
1229
  }
1224
1230
  }
1225
- if (updated.length)
1231
+ if (updated.length || cState.open && cState.open.disabled)
1226
1232
  this.view.dispatch({ effects: setActiveEffect.of(updated) });
1227
1233
  }
1228
1234
  }, {
@@ -2024,7 +2030,7 @@ returns `null`.
2024
2030
  */
2025
2031
  function completionStatus(state) {
2026
2032
  let cState = state.field(completionState, false);
2027
- return cState && cState.active.some(a => a.state == 1 /* State.Pending */) ? "pending"
2033
+ return cState && cState.active.some(a => a.isPending) ? "pending"
2028
2034
  : cState && cState.active.some(a => a.state != 0 /* State.Inactive */) ? "active" : null;
2029
2035
  }
2030
2036
  const completionArrayCache = new WeakMap;
package/dist/index.js CHANGED
@@ -814,12 +814,12 @@ class CompletionDialog {
814
814
  return selected == this.selected || selected >= this.options.length ? this
815
815
  : new CompletionDialog(this.options, makeAttrs(id, selected), this.tooltip, this.timestamp, selected, this.disabled);
816
816
  }
817
- static build(active, state, id, prev, conf) {
817
+ static build(active, state, id, prev, conf, didSetActive) {
818
+ if (prev && !didSetActive && active.some(s => s.isPending))
819
+ return prev.setDisabled();
818
820
  let options = sortOptions(active, state);
819
- if (!options.length) {
820
- return prev && active.some(a => a.state == 1 /* State.Pending */) ?
821
- new CompletionDialog(prev.options, prev.attrs, prev.tooltip, prev.timestamp, prev.selected, true) : null;
822
- }
821
+ if (!options.length)
822
+ return prev && active.some(a => a.isPending) ? prev.setDisabled() : null;
823
823
  let selected = state.facet(completionConfig).selectOnOpen ? 0 : -1;
824
824
  if (prev && prev.selected != selected && prev.selected != -1) {
825
825
  let selectedValue = prev.options[prev.selected].completion;
@@ -838,6 +838,9 @@ class CompletionDialog {
838
838
  map(changes) {
839
839
  return new CompletionDialog(this.options, this.attrs, Object.assign(Object.assign({}, this.tooltip), { pos: changes.mapPos(this.tooltip.pos) }), this.timestamp, this.selected, this.disabled);
840
840
  }
841
+ setDisabled() {
842
+ return new CompletionDialog(this.options, this.attrs, this.tooltip, this.timestamp, this.selected, true);
843
+ }
841
844
  }
842
845
  class CompletionState {
843
846
  constructor(active, id, open) {
@@ -859,15 +862,15 @@ class CompletionState {
859
862
  });
860
863
  if (active.length == this.active.length && active.every((a, i) => a == this.active[i]))
861
864
  active = this.active;
862
- let open = this.open;
865
+ let open = this.open, didSet = tr.effects.some(e => e.is(setActiveEffect));
863
866
  if (open && tr.docChanged)
864
867
  open = open.map(tr.changes);
865
868
  if (tr.selection || active.some(a => a.hasResult() && tr.changes.touchesRange(a.from, a.to)) ||
866
- !sameResults(active, this.active))
867
- open = CompletionDialog.build(active, state, this.id, open, conf);
868
- else if (open && open.disabled && !active.some(a => a.state == 1 /* State.Pending */))
869
+ !sameResults(active, this.active) || didSet)
870
+ open = CompletionDialog.build(active, state, this.id, open, conf, didSet);
871
+ else if (open && open.disabled && !active.some(a => a.isPending))
869
872
  open = null;
870
- if (!open && active.every(a => a.state != 1 /* State.Pending */) && active.some(a => a.hasResult()))
873
+ if (!open && active.every(a => !a.isPending) && active.some(a => a.hasResult()))
871
874
  active = active.map(a => a.hasResult() ? new ActiveSource(a.source, 0 /* State.Inactive */) : a);
872
875
  for (let effect of tr.effects)
873
876
  if (effect.is(setSelectedEffect))
@@ -881,9 +884,9 @@ function sameResults(a, b) {
881
884
  if (a == b)
882
885
  return true;
883
886
  for (let iA = 0, iB = 0;;) {
884
- while (iA < a.length && !a[iA].hasResult)
887
+ while (iA < a.length && !a[iA].hasResult())
885
888
  iA++;
886
- while (iB < b.length && !b[iB].hasResult)
889
+ while (iB < b.length && !b[iB].hasResult())
887
890
  iB++;
888
891
  let endA = iA == a.length, endB = iB == b.length;
889
892
  if (endA || endB)
@@ -921,12 +924,13 @@ function getUpdateType(tr, conf) {
921
924
  : tr.docChanged ? 16 /* UpdateType.ResetIfTouching */ : 0 /* UpdateType.None */;
922
925
  }
923
926
  class ActiveSource {
924
- constructor(source, state, explicitPos = -1) {
927
+ constructor(source, state, explicit = false) {
925
928
  this.source = source;
926
929
  this.state = state;
927
- this.explicitPos = explicitPos;
930
+ this.explicit = explicit;
928
931
  }
929
932
  hasResult() { return false; }
933
+ get isPending() { return this.state == 1 /* State.Pending */; }
930
934
  update(tr, conf) {
931
935
  let type = getUpdateType(tr, conf), value = this;
932
936
  if ((type & 8 /* UpdateType.Reset */) || (type & 16 /* UpdateType.ResetIfTouching */) && this.touches(tr))
@@ -936,7 +940,7 @@ class ActiveSource {
936
940
  value = value.updateFor(tr, type);
937
941
  for (let effect of tr.effects) {
938
942
  if (effect.is(startCompletionEffect))
939
- value = new ActiveSource(value.source, 1 /* State.Pending */, effect.value ? cur(tr.state) : -1);
943
+ value = new ActiveSource(value.source, 1 /* State.Pending */, effect.value);
940
944
  else if (effect.is(closeCompletionEffect))
941
945
  value = new ActiveSource(value.source, 0 /* State.Inactive */);
942
946
  else if (effect.is(setActiveEffect))
@@ -947,16 +951,15 @@ class ActiveSource {
947
951
  return value;
948
952
  }
949
953
  updateFor(tr, type) { return this.map(tr.changes); }
950
- map(changes) {
951
- return changes.empty || this.explicitPos < 0 ? this : new ActiveSource(this.source, this.state, changes.mapPos(this.explicitPos));
952
- }
954
+ map(changes) { return this; }
953
955
  touches(tr) {
954
956
  return tr.changes.touchesRange(cur(tr.state));
955
957
  }
956
958
  }
957
959
  class ActiveResult extends ActiveSource {
958
- constructor(source, explicitPos, result, from, to) {
959
- super(source, 2 /* State.Result */, explicitPos);
960
+ constructor(source, explicit, limit, result, from, to) {
961
+ super(source, 3 /* State.Result */, explicit);
962
+ this.limit = limit;
960
963
  this.result = result;
961
964
  this.from = from;
962
965
  this.to = to;
@@ -971,17 +974,16 @@ class ActiveResult extends ActiveSource {
971
974
  result = result.map(result, tr.changes);
972
975
  let from = tr.changes.mapPos(this.from), to = tr.changes.mapPos(this.to, 1);
973
976
  let pos = cur(tr.state);
974
- if ((this.explicitPos < 0 ? pos <= from : pos < this.from) ||
975
- pos > to || !result ||
976
- (type & 2 /* UpdateType.Backspacing */) && cur(tr.startState) == this.from)
977
+ if (pos > to || !result ||
978
+ (type & 2 /* UpdateType.Backspacing */) && (cur(tr.startState) == this.from || pos < this.limit))
977
979
  return new ActiveSource(this.source, type & 4 /* UpdateType.Activate */ ? 1 /* State.Pending */ : 0 /* State.Inactive */);
978
- let explicitPos = this.explicitPos < 0 ? -1 : tr.changes.mapPos(this.explicitPos);
980
+ let limit = tr.changes.mapPos(this.limit);
979
981
  if (checkValid(result.validFor, tr.state, from, to))
980
- return new ActiveResult(this.source, explicitPos, result, from, to);
982
+ return new ActiveResult(this.source, this.explicit, limit, result, from, to);
981
983
  if (result.update &&
982
- (result = result.update(result, from, to, new CompletionContext(tr.state, pos, explicitPos >= 0))))
983
- return new ActiveResult(this.source, explicitPos, result, result.from, (_a = result.to) !== null && _a !== void 0 ? _a : cur(tr.state));
984
- return new ActiveSource(this.source, 1 /* State.Pending */, explicitPos);
984
+ (result = result.update(result, from, to, new CompletionContext(tr.state, pos, false))))
985
+ return new ActiveResult(this.source, this.explicit, limit, result, result.from, (_a = result.to) !== null && _a !== void 0 ? _a : cur(tr.state));
986
+ return new ActiveSource(this.source, 1 /* State.Pending */, this.explicit);
985
987
  }
986
988
  map(mapping) {
987
989
  if (mapping.empty)
@@ -989,7 +991,7 @@ class ActiveResult extends ActiveSource {
989
991
  let result = this.result.map ? this.result.map(this.result, mapping) : this.result;
990
992
  if (!result)
991
993
  return new ActiveSource(this.source, 0 /* State.Inactive */);
992
- return new ActiveResult(this.source, this.explicitPos < 0 ? -1 : mapping.mapPos(this.explicitPos), this.result, mapping.mapPos(this.from), mapping.mapPos(this.to, 1));
994
+ return new ActiveResult(this.source, this.explicit, mapping.mapPos(this.limit), this.result, mapping.mapPos(this.from), mapping.mapPos(this.to, 1));
993
995
  }
994
996
  touches(tr) {
995
997
  return tr.changes.touchesRange(this.from, this.to);
@@ -1101,7 +1103,7 @@ const completionPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
1101
1103
  this.pendingStart = false;
1102
1104
  this.composing = 0 /* CompositionState.None */;
1103
1105
  for (let active of view.state.field(completionState).active)
1104
- if (active.state == 1 /* State.Pending */)
1106
+ if (active.isPending)
1105
1107
  this.startQuery(active);
1106
1108
  }
1107
1109
  update(update) {
@@ -1138,7 +1140,7 @@ const completionPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
1138
1140
  if (update.transactions.some(tr => tr.effects.some(e => e.is(startCompletionEffect))))
1139
1141
  this.pendingStart = true;
1140
1142
  let delay = this.pendingStart ? 50 : conf.activateOnTypingDelay;
1141
- this.debounceUpdate = cState.active.some(a => a.state == 1 /* State.Pending */ && !this.running.some(q => q.active.source == a.source))
1143
+ this.debounceUpdate = cState.active.some(a => a.isPending && !this.running.some(q => q.active.source == a.source))
1142
1144
  ? setTimeout(() => this.startUpdate(), delay) : -1;
1143
1145
  if (this.composing != 0 /* CompositionState.None */)
1144
1146
  for (let tr of update.transactions) {
@@ -1153,13 +1155,15 @@ const completionPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
1153
1155
  this.pendingStart = false;
1154
1156
  let { state } = this.view, cState = state.field(completionState);
1155
1157
  for (let active of cState.active) {
1156
- if (active.state == 1 /* State.Pending */ && !this.running.some(r => r.active.source == active.source))
1158
+ if (active.isPending && !this.running.some(r => r.active.source == active.source))
1157
1159
  this.startQuery(active);
1158
1160
  }
1161
+ if (this.running.length && cState.open && cState.open.disabled)
1162
+ this.debounceAccept = setTimeout(() => this.accept(), this.view.state.facet(completionConfig).updateSyncTime);
1159
1163
  }
1160
1164
  startQuery(active) {
1161
1165
  let { state } = this.view, pos = cur(state);
1162
- let context = new CompletionContext(state, pos, active.explicitPos == pos, this.view);
1166
+ let context = new CompletionContext(state, pos, active.explicit, this.view);
1163
1167
  let pending = new RunningQuery(active, context);
1164
1168
  this.running.push(pending);
1165
1169
  Promise.resolve(active.source(context)).then(result => {
@@ -1186,14 +1190,16 @@ const completionPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
1186
1190
  clearTimeout(this.debounceAccept);
1187
1191
  this.debounceAccept = -1;
1188
1192
  let updated = [];
1189
- let conf = this.view.state.facet(completionConfig);
1193
+ let conf = this.view.state.facet(completionConfig), cState = this.view.state.field(completionState);
1190
1194
  for (let i = 0; i < this.running.length; i++) {
1191
1195
  let query = this.running[i];
1192
1196
  if (query.done === undefined)
1193
1197
  continue;
1194
1198
  this.running.splice(i--, 1);
1195
1199
  if (query.done) {
1196
- let active = new ActiveResult(query.active.source, query.active.explicitPos, query.done, query.done.from, (_a = query.done.to) !== null && _a !== void 0 ? _a : cur(query.updates.length ? query.updates[0].startState : this.view.state));
1200
+ let pos = cur(query.updates.length ? query.updates[0].startState : this.view.state);
1201
+ let limit = Math.min(pos, query.done.from + (query.active.explicit ? 0 : 1));
1202
+ let active = new ActiveResult(query.active.source, query.active.explicit, limit, query.done, query.done.from, (_a = query.done.to) !== null && _a !== void 0 ? _a : pos);
1197
1203
  // Replay the transactions that happened since the start of
1198
1204
  // the request and see if that preserves the result
1199
1205
  for (let tr of query.updates)
@@ -1203,15 +1209,15 @@ const completionPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
1203
1209
  continue;
1204
1210
  }
1205
1211
  }
1206
- let current = this.view.state.field(completionState).active.find(a => a.source == query.active.source);
1207
- if (current && current.state == 1 /* State.Pending */) {
1212
+ let current = cState.active.find(a => a.source == query.active.source);
1213
+ if (current && current.isPending) {
1208
1214
  if (query.done == null) {
1209
1215
  // Explicitly failed. Should clear the pending status if it
1210
1216
  // hasn't been re-set in the meantime.
1211
1217
  let active = new ActiveSource(query.active.source, 0 /* State.Inactive */);
1212
1218
  for (let tr of query.updates)
1213
1219
  active = active.update(tr, conf);
1214
- if (active.state != 1 /* State.Pending */)
1220
+ if (!active.isPending)
1215
1221
  updated.push(active);
1216
1222
  }
1217
1223
  else {
@@ -1220,7 +1226,7 @@ const completionPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
1220
1226
  }
1221
1227
  }
1222
1228
  }
1223
- if (updated.length)
1229
+ if (updated.length || cState.open && cState.open.disabled)
1224
1230
  this.view.dispatch({ effects: setActiveEffect.of(updated) });
1225
1231
  }
1226
1232
  }, {
@@ -2022,7 +2028,7 @@ returns `null`.
2022
2028
  */
2023
2029
  function completionStatus(state) {
2024
2030
  let cState = state.field(completionState, false);
2025
- return cState && cState.active.some(a => a.state == 1 /* State.Pending */) ? "pending"
2031
+ return cState && cState.active.some(a => a.isPending) ? "pending"
2026
2032
  : cState && cState.active.some(a => a.state != 0 /* State.Inactive */) ? "active" : null;
2027
2033
  }
2028
2034
  const completionArrayCache = /*@__PURE__*/new WeakMap;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemirror/autocomplete",
3
- "version": "6.18.1",
3
+ "version": "6.18.3",
4
4
  "description": "Autocompletion for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",