@codemirror/autocomplete 0.19.12 → 0.19.13

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,11 @@
1
+ ## 0.19.13 (2022-02-18)
2
+
3
+ ### Bug fixes
4
+
5
+ Fix an issue where the completion tooltip stayed open if it was explicitly opened and the user backspaced past its start.
6
+
7
+ Stop snippet filling when a change happens across one of the snippet fields' boundaries.
8
+
1
9
  ## 0.19.12 (2022-01-11)
2
10
 
3
11
  ### Bug fixes
package/dist/index.cjs CHANGED
@@ -741,7 +741,9 @@ class ActiveResult extends ActiveSource {
741
741
  handleUserEvent(tr, type, conf) {
742
742
  let from = tr.changes.mapPos(this.from), to = tr.changes.mapPos(this.to, 1);
743
743
  let pos = cur(tr.state);
744
- if ((this.explicitPos > -1 ? pos < from : pos <= from) || pos > to)
744
+ if ((this.explicitPos < 0 ? pos <= from : pos < this.from) ||
745
+ pos > to ||
746
+ type == "delete" && cur(tr.startState) == this.from)
745
747
  return new ActiveSource(this.source, type == "input" && conf.activateOnTyping ? 1 /* Pending */ : 0 /* Inactive */);
746
748
  let explicitPos = this.explicitPos < 0 ? -1 : tr.changes.mapPos(this.explicitPos);
747
749
  if (this.span && (from == to || this.span.test(tr.state.sliceDoc(from, to))))
@@ -1093,7 +1095,9 @@ class FieldRange {
1093
1095
  this.to = to;
1094
1096
  }
1095
1097
  map(changes) {
1096
- return new FieldRange(this.field, changes.mapPos(this.from, -1), changes.mapPos(this.to, 1));
1098
+ let from = changes.mapPos(this.from, -1, state.MapMode.TrackDel);
1099
+ let to = changes.mapPos(this.to, 1, state.MapMode.TrackDel);
1100
+ return from == null || to == null ? null : new FieldRange(this.field, from, to);
1097
1101
  }
1098
1102
  }
1099
1103
  class Snippet {
@@ -1162,7 +1166,14 @@ class ActiveSnippet {
1162
1166
  this.deco = view.Decoration.set(ranges.map(r => (r.from == r.to ? fieldMarker : fieldRange).range(r.from, r.to)));
1163
1167
  }
1164
1168
  map(changes) {
1165
- return new ActiveSnippet(this.ranges.map(r => r.map(changes)), this.active);
1169
+ let ranges = [];
1170
+ for (let r of this.ranges) {
1171
+ let mapped = r.map(changes);
1172
+ if (!mapped)
1173
+ return null;
1174
+ ranges.push(mapped);
1175
+ }
1176
+ return new ActiveSnippet(ranges, this.active);
1166
1177
  }
1167
1178
  selectionInsideField(sel) {
1168
1179
  return sel.ranges.every(range => this.ranges.some(r => r.field == this.active && r.from <= range.from && r.to >= range.to));
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Annotation, Facet, combineConfig, StateEffect, StateField, Prec, EditorSelection, Text } from '@codemirror/state';
1
+ import { Annotation, Facet, combineConfig, StateEffect, StateField, Prec, EditorSelection, Text, MapMode } from '@codemirror/state';
2
2
  import { Direction, logException, EditorView, ViewPlugin, Decoration, WidgetType, keymap } from '@codemirror/view';
3
3
  import { showTooltip, getTooltip } from '@codemirror/tooltip';
4
4
  import { syntaxTree, indentUnit } from '@codemirror/language';
@@ -737,7 +737,9 @@ class ActiveResult extends ActiveSource {
737
737
  handleUserEvent(tr, type, conf) {
738
738
  let from = tr.changes.mapPos(this.from), to = tr.changes.mapPos(this.to, 1);
739
739
  let pos = cur(tr.state);
740
- if ((this.explicitPos > -1 ? pos < from : pos <= from) || pos > to)
740
+ if ((this.explicitPos < 0 ? pos <= from : pos < this.from) ||
741
+ pos > to ||
742
+ type == "delete" && cur(tr.startState) == this.from)
741
743
  return new ActiveSource(this.source, type == "input" && conf.activateOnTyping ? 1 /* Pending */ : 0 /* Inactive */);
742
744
  let explicitPos = this.explicitPos < 0 ? -1 : tr.changes.mapPos(this.explicitPos);
743
745
  if (this.span && (from == to || this.span.test(tr.state.sliceDoc(from, to))))
@@ -1089,7 +1091,9 @@ class FieldRange {
1089
1091
  this.to = to;
1090
1092
  }
1091
1093
  map(changes) {
1092
- return new FieldRange(this.field, changes.mapPos(this.from, -1), changes.mapPos(this.to, 1));
1094
+ let from = changes.mapPos(this.from, -1, MapMode.TrackDel);
1095
+ let to = changes.mapPos(this.to, 1, MapMode.TrackDel);
1096
+ return from == null || to == null ? null : new FieldRange(this.field, from, to);
1093
1097
  }
1094
1098
  }
1095
1099
  class Snippet {
@@ -1158,7 +1162,14 @@ class ActiveSnippet {
1158
1162
  this.deco = Decoration.set(ranges.map(r => (r.from == r.to ? fieldMarker : fieldRange).range(r.from, r.to)));
1159
1163
  }
1160
1164
  map(changes) {
1161
- return new ActiveSnippet(this.ranges.map(r => r.map(changes)), this.active);
1165
+ let ranges = [];
1166
+ for (let r of this.ranges) {
1167
+ let mapped = r.map(changes);
1168
+ if (!mapped)
1169
+ return null;
1170
+ ranges.push(mapped);
1171
+ }
1172
+ return new ActiveSnippet(ranges, this.active);
1162
1173
  }
1163
1174
  selectionInsideField(sel) {
1164
1175
  return sel.ranges.every(range => this.ranges.some(r => r.field == this.active && r.from <= range.from && r.to >= range.to));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemirror/autocomplete",
3
- "version": "0.19.12",
3
+ "version": "0.19.13",
4
4
  "description": "Autocompletion for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",