@codemirror/autocomplete 6.5.1 → 6.6.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.6.0 (2023-04-27)
2
+
3
+ ### Bug fixes
4
+
5
+ Fix a bug in `insertCompletionText` that caused it to replace the wrong range when a result set's `to` fell after the cursor.
6
+
7
+ ### New features
8
+
9
+ Functions returned by `snippet` can now be called without a completion object.
10
+
1
11
  ## 6.5.1 (2023-04-13)
2
12
 
3
13
  ### Bug fixes
package/dist/index.cjs CHANGED
@@ -166,14 +166,14 @@ completion's text in the main selection range, and any other
166
166
  selection range that has the same text in front of it.
167
167
  */
168
168
  function insertCompletionText(state$1, text, from, to) {
169
- let { main } = state$1.selection, len = to - from;
169
+ let { main } = state$1.selection, fromOff = from - main.from, toOff = to - main.from;
170
170
  return Object.assign(Object.assign({}, state$1.changeByRange(range => {
171
- if (range != main && len &&
172
- state$1.sliceDoc(range.from - len, range.from + to - main.from) != state$1.sliceDoc(from, to))
171
+ if (range != main && from != to &&
172
+ state$1.sliceDoc(range.from + fromOff, range.from + toOff) != state$1.sliceDoc(from, to))
173
173
  return { range };
174
174
  return {
175
- changes: { from: range.from - len, to: to == main.from ? range.to : range.from + to - main.from, insert: text },
176
- range: state.EditorSelection.cursor(range.from - len + text.length)
175
+ changes: { from: range.from + fromOff, to: to == main.from ? range.to : range.from + toOff, insert: text },
176
+ range: state.EditorSelection.cursor(range.from + fromOff + text.length)
177
177
  };
178
178
  })), { userEvent: "input.complete" });
179
179
  }
@@ -1432,7 +1432,7 @@ function snippet(template) {
1432
1432
  let spec = {
1433
1433
  changes: { from, to, insert: state.Text.of(text) },
1434
1434
  scrollIntoView: true,
1435
- annotations: pickedCompletion.of(completion)
1435
+ annotations: completion ? pickedCompletion.of(completion) : undefined
1436
1436
  };
1437
1437
  if (ranges.length)
1438
1438
  spec.selection = fieldSelection(ranges, 0);
package/dist/index.d.ts CHANGED
@@ -384,7 +384,7 @@ interpreted as indicating a placeholder.
384
384
  declare function snippet(template: string): (editor: {
385
385
  state: EditorState;
386
386
  dispatch: (tr: Transaction) => void;
387
- }, completion: Completion, from: number, to: number) => void;
387
+ }, completion: Completion | null, from: number, to: number) => void;
388
388
  /**
389
389
  A command that clears the active snippet, if any.
390
390
  */
package/dist/index.js CHANGED
@@ -162,14 +162,14 @@ completion's text in the main selection range, and any other
162
162
  selection range that has the same text in front of it.
163
163
  */
164
164
  function insertCompletionText(state, text, from, to) {
165
- let { main } = state.selection, len = to - from;
165
+ let { main } = state.selection, fromOff = from - main.from, toOff = to - main.from;
166
166
  return Object.assign(Object.assign({}, state.changeByRange(range => {
167
- if (range != main && len &&
168
- state.sliceDoc(range.from - len, range.from + to - main.from) != state.sliceDoc(from, to))
167
+ if (range != main && from != to &&
168
+ state.sliceDoc(range.from + fromOff, range.from + toOff) != state.sliceDoc(from, to))
169
169
  return { range };
170
170
  return {
171
- changes: { from: range.from - len, to: to == main.from ? range.to : range.from + to - main.from, insert: text },
172
- range: EditorSelection.cursor(range.from - len + text.length)
171
+ changes: { from: range.from + fromOff, to: to == main.from ? range.to : range.from + toOff, insert: text },
172
+ range: EditorSelection.cursor(range.from + fromOff + text.length)
173
173
  };
174
174
  })), { userEvent: "input.complete" });
175
175
  }
@@ -1428,7 +1428,7 @@ function snippet(template) {
1428
1428
  let spec = {
1429
1429
  changes: { from, to, insert: Text.of(text) },
1430
1430
  scrollIntoView: true,
1431
- annotations: pickedCompletion.of(completion)
1431
+ annotations: completion ? pickedCompletion.of(completion) : undefined
1432
1432
  };
1433
1433
  if (ranges.length)
1434
1434
  spec.selection = fieldSelection(ranges, 0);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemirror/autocomplete",
3
- "version": "6.5.1",
3
+ "version": "6.6.0",
4
4
  "description": "Autocompletion for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",