@codemirror/autocomplete 6.18.2 → 6.18.4

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.4 (2024-12-17)
2
+
3
+ ### Bug fixes
4
+
5
+ Align the behavior of snippet completions with text completions in that they overwrite the selected text.
6
+
7
+ ## 6.18.3 (2024-11-13)
8
+
9
+ ### Bug fixes
10
+
11
+ 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.
12
+
1
13
  ## 6.18.2 (2024-10-30)
2
14
 
3
15
  ### Bug fixes
package/dist/index.cjs CHANGED
@@ -817,11 +817,11 @@ class CompletionDialog {
817
817
  : new CompletionDialog(this.options, makeAttrs(id, selected), this.tooltip, this.timestamp, selected, this.disabled);
818
818
  }
819
819
  static build(active, state, id, prev, conf, didSetActive) {
820
- if (prev && !didSetActive && active.some(s => s.state == 1 /* State.Pending */))
820
+ if (prev && !didSetActive && active.some(s => s.isPending))
821
821
  return prev.setDisabled();
822
822
  let options = sortOptions(active, state);
823
823
  if (!options.length)
824
- return prev && active.some(a => a.state == 1 /* State.Pending */) ? prev.setDisabled() : null;
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;
@@ -870,9 +870,9 @@ class CompletionState {
870
870
  if (tr.selection || active.some(a => a.hasResult() && tr.changes.touchesRange(a.from, a.to)) ||
871
871
  !sameResults(active, this.active) || didSet)
872
872
  open = CompletionDialog.build(active, state, this.id, open, conf, didSet);
873
- else if (open && open.disabled && !active.some(a => a.state == 1 /* State.Pending */))
873
+ else if (open && open.disabled && !active.some(a => a.isPending))
874
874
  open = null;
875
- 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()))
876
876
  active = active.map(a => a.hasResult() ? new ActiveSource(a.source, 0 /* State.Inactive */) : a);
877
877
  for (let effect of tr.effects)
878
878
  if (effect.is(setSelectedEffect))
@@ -886,9 +886,9 @@ function sameResults(a, b) {
886
886
  if (a == b)
887
887
  return true;
888
888
  for (let iA = 0, iB = 0;;) {
889
- while (iA < a.length && !a[iA].hasResult)
889
+ while (iA < a.length && !a[iA].hasResult())
890
890
  iA++;
891
- while (iB < b.length && !b[iB].hasResult)
891
+ while (iB < b.length && !b[iB].hasResult())
892
892
  iB++;
893
893
  let endA = iA == a.length, endB = iB == b.length;
894
894
  if (endA || endB)
@@ -926,12 +926,13 @@ function getUpdateType(tr, conf) {
926
926
  : tr.docChanged ? 16 /* UpdateType.ResetIfTouching */ : 0 /* UpdateType.None */;
927
927
  }
928
928
  class ActiveSource {
929
- constructor(source, state, explicitPos = -1) {
929
+ constructor(source, state, explicit = false) {
930
930
  this.source = source;
931
931
  this.state = state;
932
- this.explicitPos = explicitPos;
932
+ this.explicit = explicit;
933
933
  }
934
934
  hasResult() { return false; }
935
+ get isPending() { return this.state == 1 /* State.Pending */; }
935
936
  update(tr, conf) {
936
937
  let type = getUpdateType(tr, conf), value = this;
937
938
  if ((type & 8 /* UpdateType.Reset */) || (type & 16 /* UpdateType.ResetIfTouching */) && this.touches(tr))
@@ -941,7 +942,7 @@ class ActiveSource {
941
942
  value = value.updateFor(tr, type);
942
943
  for (let effect of tr.effects) {
943
944
  if (effect.is(startCompletionEffect))
944
- 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);
945
946
  else if (effect.is(closeCompletionEffect))
946
947
  value = new ActiveSource(value.source, 0 /* State.Inactive */);
947
948
  else if (effect.is(setActiveEffect))
@@ -952,16 +953,15 @@ class ActiveSource {
952
953
  return value;
953
954
  }
954
955
  updateFor(tr, type) { return this.map(tr.changes); }
955
- map(changes) {
956
- return changes.empty || this.explicitPos < 0 ? this : new ActiveSource(this.source, this.state, changes.mapPos(this.explicitPos));
957
- }
956
+ map(changes) { return this; }
958
957
  touches(tr) {
959
958
  return tr.changes.touchesRange(cur(tr.state));
960
959
  }
961
960
  }
962
961
  class ActiveResult extends ActiveSource {
963
- constructor(source, explicitPos, result, from, to) {
964
- 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;
965
965
  this.result = result;
966
966
  this.from = from;
967
967
  this.to = to;
@@ -976,17 +976,16 @@ class ActiveResult extends ActiveSource {
976
976
  result = result.map(result, tr.changes);
977
977
  let from = tr.changes.mapPos(this.from), to = tr.changes.mapPos(this.to, 1);
978
978
  let pos = cur(tr.state);
979
- if ((this.explicitPos < 0 ? pos <= from : pos < this.from) ||
980
- pos > to || !result ||
981
- (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))
982
981
  return new ActiveSource(this.source, type & 4 /* UpdateType.Activate */ ? 1 /* State.Pending */ : 0 /* State.Inactive */);
983
- let explicitPos = this.explicitPos < 0 ? -1 : tr.changes.mapPos(this.explicitPos);
982
+ let limit = tr.changes.mapPos(this.limit);
984
983
  if (checkValid(result.validFor, tr.state, from, to))
985
- return new ActiveResult(this.source, explicitPos, result, from, to);
984
+ return new ActiveResult(this.source, this.explicit, limit, result, from, to);
986
985
  if (result.update &&
987
- (result = result.update(result, from, to, new CompletionContext(tr.state, pos, explicitPos >= 0))))
988
- return new ActiveResult(this.source, explicitPos, result, result.from, (_a = result.to) !== null && _a !== void 0 ? _a : cur(tr.state));
989
- 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);
990
989
  }
991
990
  map(mapping) {
992
991
  if (mapping.empty)
@@ -994,7 +993,7 @@ class ActiveResult extends ActiveSource {
994
993
  let result = this.result.map ? this.result.map(this.result, mapping) : this.result;
995
994
  if (!result)
996
995
  return new ActiveSource(this.source, 0 /* State.Inactive */);
997
- 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));
998
997
  }
999
998
  touches(tr) {
1000
999
  return tr.changes.touchesRange(this.from, this.to);
@@ -1106,7 +1105,7 @@ const completionPlugin = view.ViewPlugin.fromClass(class {
1106
1105
  this.pendingStart = false;
1107
1106
  this.composing = 0 /* CompositionState.None */;
1108
1107
  for (let active of view.state.field(completionState).active)
1109
- if (active.state == 1 /* State.Pending */)
1108
+ if (active.isPending)
1110
1109
  this.startQuery(active);
1111
1110
  }
1112
1111
  update(update) {
@@ -1143,7 +1142,7 @@ const completionPlugin = view.ViewPlugin.fromClass(class {
1143
1142
  if (update.transactions.some(tr => tr.effects.some(e => e.is(startCompletionEffect))))
1144
1143
  this.pendingStart = true;
1145
1144
  let delay = this.pendingStart ? 50 : conf.activateOnTypingDelay;
1146
- 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))
1147
1146
  ? setTimeout(() => this.startUpdate(), delay) : -1;
1148
1147
  if (this.composing != 0 /* CompositionState.None */)
1149
1148
  for (let tr of update.transactions) {
@@ -1158,7 +1157,7 @@ const completionPlugin = view.ViewPlugin.fromClass(class {
1158
1157
  this.pendingStart = false;
1159
1158
  let { state } = this.view, cState = state.field(completionState);
1160
1159
  for (let active of cState.active) {
1161
- 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))
1162
1161
  this.startQuery(active);
1163
1162
  }
1164
1163
  if (this.running.length && cState.open && cState.open.disabled)
@@ -1166,7 +1165,7 @@ const completionPlugin = view.ViewPlugin.fromClass(class {
1166
1165
  }
1167
1166
  startQuery(active) {
1168
1167
  let { state } = this.view, pos = cur(state);
1169
- let context = new CompletionContext(state, pos, active.explicitPos == pos, this.view);
1168
+ let context = new CompletionContext(state, pos, active.explicit, this.view);
1170
1169
  let pending = new RunningQuery(active, context);
1171
1170
  this.running.push(pending);
1172
1171
  Promise.resolve(active.source(context)).then(result => {
@@ -1200,7 +1199,9 @@ const completionPlugin = view.ViewPlugin.fromClass(class {
1200
1199
  continue;
1201
1200
  this.running.splice(i--, 1);
1202
1201
  if (query.done) {
1203
- 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);
1204
1205
  // Replay the transactions that happened since the start of
1205
1206
  // the request and see if that preserves the result
1206
1207
  for (let tr of query.updates)
@@ -1211,14 +1212,14 @@ const completionPlugin = view.ViewPlugin.fromClass(class {
1211
1212
  }
1212
1213
  }
1213
1214
  let current = cState.active.find(a => a.source == query.active.source);
1214
- if (current && current.state == 1 /* State.Pending */) {
1215
+ if (current && current.isPending) {
1215
1216
  if (query.done == null) {
1216
1217
  // Explicitly failed. Should clear the pending status if it
1217
1218
  // hasn't been re-set in the meantime.
1218
1219
  let active = new ActiveSource(query.active.source, 0 /* State.Inactive */);
1219
1220
  for (let tr of query.updates)
1220
1221
  active = active.update(tr, conf);
1221
- if (active.state != 1 /* State.Pending */)
1222
+ if (!active.isPending)
1222
1223
  updated.push(active);
1223
1224
  }
1224
1225
  else {
@@ -1559,8 +1560,9 @@ function snippet(template) {
1559
1560
  let snippet = Snippet.parse(template);
1560
1561
  return (editor, completion, from, to) => {
1561
1562
  let { text, ranges } = snippet.instantiate(editor.state, from);
1563
+ let { main } = editor.state.selection;
1562
1564
  let spec = {
1563
- changes: { from, to, insert: state.Text.of(text) },
1565
+ changes: { from, to: to == main.from ? main.to : to, insert: state.Text.of(text) },
1564
1566
  scrollIntoView: true,
1565
1567
  annotations: completion ? [pickedCompletion.of(completion), state.Transaction.userEvent.of("input.complete")] : undefined
1566
1568
  };
@@ -2029,7 +2031,7 @@ returns `null`.
2029
2031
  */
2030
2032
  function completionStatus(state) {
2031
2033
  let cState = state.field(completionState, false);
2032
- return cState && cState.active.some(a => a.state == 1 /* State.Pending */) ? "pending"
2034
+ return cState && cState.active.some(a => a.isPending) ? "pending"
2033
2035
  : cState && cState.active.some(a => a.state != 0 /* State.Inactive */) ? "active" : null;
2034
2036
  }
2035
2037
  const completionArrayCache = new WeakMap;
package/dist/index.js CHANGED
@@ -815,11 +815,11 @@ class CompletionDialog {
815
815
  : new CompletionDialog(this.options, makeAttrs(id, selected), this.tooltip, this.timestamp, selected, this.disabled);
816
816
  }
817
817
  static build(active, state, id, prev, conf, didSetActive) {
818
- if (prev && !didSetActive && active.some(s => s.state == 1 /* State.Pending */))
818
+ if (prev && !didSetActive && active.some(s => s.isPending))
819
819
  return prev.setDisabled();
820
820
  let options = sortOptions(active, state);
821
821
  if (!options.length)
822
- return prev && active.some(a => a.state == 1 /* State.Pending */) ? prev.setDisabled() : null;
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;
@@ -868,9 +868,9 @@ class CompletionState {
868
868
  if (tr.selection || active.some(a => a.hasResult() && tr.changes.touchesRange(a.from, a.to)) ||
869
869
  !sameResults(active, this.active) || didSet)
870
870
  open = CompletionDialog.build(active, state, this.id, open, conf, didSet);
871
- else if (open && open.disabled && !active.some(a => a.state == 1 /* State.Pending */))
871
+ else if (open && open.disabled && !active.some(a => a.isPending))
872
872
  open = null;
873
- 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()))
874
874
  active = active.map(a => a.hasResult() ? new ActiveSource(a.source, 0 /* State.Inactive */) : a);
875
875
  for (let effect of tr.effects)
876
876
  if (effect.is(setSelectedEffect))
@@ -884,9 +884,9 @@ function sameResults(a, b) {
884
884
  if (a == b)
885
885
  return true;
886
886
  for (let iA = 0, iB = 0;;) {
887
- while (iA < a.length && !a[iA].hasResult)
887
+ while (iA < a.length && !a[iA].hasResult())
888
888
  iA++;
889
- while (iB < b.length && !b[iB].hasResult)
889
+ while (iB < b.length && !b[iB].hasResult())
890
890
  iB++;
891
891
  let endA = iA == a.length, endB = iB == b.length;
892
892
  if (endA || endB)
@@ -924,12 +924,13 @@ function getUpdateType(tr, conf) {
924
924
  : tr.docChanged ? 16 /* UpdateType.ResetIfTouching */ : 0 /* UpdateType.None */;
925
925
  }
926
926
  class ActiveSource {
927
- constructor(source, state, explicitPos = -1) {
927
+ constructor(source, state, explicit = false) {
928
928
  this.source = source;
929
929
  this.state = state;
930
- this.explicitPos = explicitPos;
930
+ this.explicit = explicit;
931
931
  }
932
932
  hasResult() { return false; }
933
+ get isPending() { return this.state == 1 /* State.Pending */; }
933
934
  update(tr, conf) {
934
935
  let type = getUpdateType(tr, conf), value = this;
935
936
  if ((type & 8 /* UpdateType.Reset */) || (type & 16 /* UpdateType.ResetIfTouching */) && this.touches(tr))
@@ -939,7 +940,7 @@ class ActiveSource {
939
940
  value = value.updateFor(tr, type);
940
941
  for (let effect of tr.effects) {
941
942
  if (effect.is(startCompletionEffect))
942
- 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);
943
944
  else if (effect.is(closeCompletionEffect))
944
945
  value = new ActiveSource(value.source, 0 /* State.Inactive */);
945
946
  else if (effect.is(setActiveEffect))
@@ -950,16 +951,15 @@ class ActiveSource {
950
951
  return value;
951
952
  }
952
953
  updateFor(tr, type) { return this.map(tr.changes); }
953
- map(changes) {
954
- return changes.empty || this.explicitPos < 0 ? this : new ActiveSource(this.source, this.state, changes.mapPos(this.explicitPos));
955
- }
954
+ map(changes) { return this; }
956
955
  touches(tr) {
957
956
  return tr.changes.touchesRange(cur(tr.state));
958
957
  }
959
958
  }
960
959
  class ActiveResult extends ActiveSource {
961
- constructor(source, explicitPos, result, from, to) {
962
- 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;
963
963
  this.result = result;
964
964
  this.from = from;
965
965
  this.to = to;
@@ -974,17 +974,16 @@ class ActiveResult extends ActiveSource {
974
974
  result = result.map(result, tr.changes);
975
975
  let from = tr.changes.mapPos(this.from), to = tr.changes.mapPos(this.to, 1);
976
976
  let pos = cur(tr.state);
977
- if ((this.explicitPos < 0 ? pos <= from : pos < this.from) ||
978
- pos > to || !result ||
979
- (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))
980
979
  return new ActiveSource(this.source, type & 4 /* UpdateType.Activate */ ? 1 /* State.Pending */ : 0 /* State.Inactive */);
981
- let explicitPos = this.explicitPos < 0 ? -1 : tr.changes.mapPos(this.explicitPos);
980
+ let limit = tr.changes.mapPos(this.limit);
982
981
  if (checkValid(result.validFor, tr.state, from, to))
983
- return new ActiveResult(this.source, explicitPos, result, from, to);
982
+ return new ActiveResult(this.source, this.explicit, limit, result, from, to);
984
983
  if (result.update &&
985
- (result = result.update(result, from, to, new CompletionContext(tr.state, pos, explicitPos >= 0))))
986
- return new ActiveResult(this.source, explicitPos, result, result.from, (_a = result.to) !== null && _a !== void 0 ? _a : cur(tr.state));
987
- 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);
988
987
  }
989
988
  map(mapping) {
990
989
  if (mapping.empty)
@@ -992,7 +991,7 @@ class ActiveResult extends ActiveSource {
992
991
  let result = this.result.map ? this.result.map(this.result, mapping) : this.result;
993
992
  if (!result)
994
993
  return new ActiveSource(this.source, 0 /* State.Inactive */);
995
- 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));
996
995
  }
997
996
  touches(tr) {
998
997
  return tr.changes.touchesRange(this.from, this.to);
@@ -1104,7 +1103,7 @@ const completionPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
1104
1103
  this.pendingStart = false;
1105
1104
  this.composing = 0 /* CompositionState.None */;
1106
1105
  for (let active of view.state.field(completionState).active)
1107
- if (active.state == 1 /* State.Pending */)
1106
+ if (active.isPending)
1108
1107
  this.startQuery(active);
1109
1108
  }
1110
1109
  update(update) {
@@ -1141,7 +1140,7 @@ const completionPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
1141
1140
  if (update.transactions.some(tr => tr.effects.some(e => e.is(startCompletionEffect))))
1142
1141
  this.pendingStart = true;
1143
1142
  let delay = this.pendingStart ? 50 : conf.activateOnTypingDelay;
1144
- 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))
1145
1144
  ? setTimeout(() => this.startUpdate(), delay) : -1;
1146
1145
  if (this.composing != 0 /* CompositionState.None */)
1147
1146
  for (let tr of update.transactions) {
@@ -1156,7 +1155,7 @@ const completionPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
1156
1155
  this.pendingStart = false;
1157
1156
  let { state } = this.view, cState = state.field(completionState);
1158
1157
  for (let active of cState.active) {
1159
- 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))
1160
1159
  this.startQuery(active);
1161
1160
  }
1162
1161
  if (this.running.length && cState.open && cState.open.disabled)
@@ -1164,7 +1163,7 @@ const completionPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
1164
1163
  }
1165
1164
  startQuery(active) {
1166
1165
  let { state } = this.view, pos = cur(state);
1167
- let context = new CompletionContext(state, pos, active.explicitPos == pos, this.view);
1166
+ let context = new CompletionContext(state, pos, active.explicit, this.view);
1168
1167
  let pending = new RunningQuery(active, context);
1169
1168
  this.running.push(pending);
1170
1169
  Promise.resolve(active.source(context)).then(result => {
@@ -1198,7 +1197,9 @@ const completionPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
1198
1197
  continue;
1199
1198
  this.running.splice(i--, 1);
1200
1199
  if (query.done) {
1201
- 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);
1202
1203
  // Replay the transactions that happened since the start of
1203
1204
  // the request and see if that preserves the result
1204
1205
  for (let tr of query.updates)
@@ -1209,14 +1210,14 @@ const completionPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
1209
1210
  }
1210
1211
  }
1211
1212
  let current = cState.active.find(a => a.source == query.active.source);
1212
- if (current && current.state == 1 /* State.Pending */) {
1213
+ if (current && current.isPending) {
1213
1214
  if (query.done == null) {
1214
1215
  // Explicitly failed. Should clear the pending status if it
1215
1216
  // hasn't been re-set in the meantime.
1216
1217
  let active = new ActiveSource(query.active.source, 0 /* State.Inactive */);
1217
1218
  for (let tr of query.updates)
1218
1219
  active = active.update(tr, conf);
1219
- if (active.state != 1 /* State.Pending */)
1220
+ if (!active.isPending)
1220
1221
  updated.push(active);
1221
1222
  }
1222
1223
  else {
@@ -1557,8 +1558,9 @@ function snippet(template) {
1557
1558
  let snippet = Snippet.parse(template);
1558
1559
  return (editor, completion, from, to) => {
1559
1560
  let { text, ranges } = snippet.instantiate(editor.state, from);
1561
+ let { main } = editor.state.selection;
1560
1562
  let spec = {
1561
- changes: { from, to, insert: Text.of(text) },
1563
+ changes: { from, to: to == main.from ? main.to : to, insert: Text.of(text) },
1562
1564
  scrollIntoView: true,
1563
1565
  annotations: completion ? [pickedCompletion.of(completion), Transaction.userEvent.of("input.complete")] : undefined
1564
1566
  };
@@ -2027,7 +2029,7 @@ returns `null`.
2027
2029
  */
2028
2030
  function completionStatus(state) {
2029
2031
  let cState = state.field(completionState, false);
2030
- return cState && cState.active.some(a => a.state == 1 /* State.Pending */) ? "pending"
2032
+ return cState && cState.active.some(a => a.isPending) ? "pending"
2031
2033
  : cState && cState.active.some(a => a.state != 0 /* State.Inactive */) ? "active" : null;
2032
2034
  }
2033
2035
  const completionArrayCache = /*@__PURE__*/new WeakMap;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemirror/autocomplete",
3
- "version": "6.18.2",
3
+ "version": "6.18.4",
4
4
  "description": "Autocompletion for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",
@@ -31,12 +31,6 @@
31
31
  "@codemirror/view": "^6.17.0",
32
32
  "@lezer/common": "^1.0.0"
33
33
  },
34
- "peerDependencies": {
35
- "@codemirror/language": "^6.0.0",
36
- "@codemirror/state": "^6.0.0",
37
- "@codemirror/view": "^6.0.0",
38
- "@lezer/common": "^1.0.0"
39
- },
40
34
  "devDependencies": {
41
35
  "@codemirror/buildhelper": "^1.0.0"
42
36
  },