@codemirror/autocomplete 6.18.5 → 6.18.7

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,17 @@
1
+ ## 6.18.7 (2025-09-02)
2
+
3
+ ### Bug fixes
4
+
5
+ Add a binding for Alt-i to trigger `startCompletion`, following VS Code's current default bindings.
6
+
7
+ Improve handling of nested fields in snippets.
8
+
9
+ ## 6.18.6 (2025-02-12)
10
+
11
+ ### Bug fixes
12
+
13
+ Fix an issue where the closing character for double-angle quotation marks and full-width brackets was computed incorrectly.
14
+
1
15
  ## 6.18.5 (2025-02-11)
2
16
 
3
17
  ### Bug fixes
package/dist/index.cjs CHANGED
@@ -189,16 +189,20 @@ selection range that has the same text in front of it.
189
189
  */
190
190
  function insertCompletionText(state$1, text, from, to) {
191
191
  let { main } = state$1.selection, fromOff = from - main.from, toOff = to - main.from;
192
- return Object.assign(Object.assign({}, state$1.changeByRange(range => {
193
- if (range != main && from != to &&
194
- state$1.sliceDoc(range.from + fromOff, range.from + toOff) != state$1.sliceDoc(from, to))
195
- return { range };
196
- let lines = state$1.toText(text);
197
- return {
198
- changes: { from: range.from + fromOff, to: to == main.from ? range.to : range.from + toOff, insert: lines },
199
- range: state.EditorSelection.cursor(range.from + fromOff + lines.length)
200
- };
201
- })), { scrollIntoView: true, userEvent: "input.complete" });
192
+ return {
193
+ ...state$1.changeByRange(range => {
194
+ if (range != main && from != to &&
195
+ state$1.sliceDoc(range.from + fromOff, range.from + toOff) != state$1.sliceDoc(from, to))
196
+ return { range };
197
+ let lines = state$1.toText(text);
198
+ return {
199
+ changes: { from: range.from + fromOff, to: to == main.from ? range.to : range.from + toOff, insert: lines },
200
+ range: state.EditorSelection.cursor(range.from + fromOff + lines.length)
201
+ };
202
+ }),
203
+ scrollIntoView: true,
204
+ userEvent: "input.complete"
205
+ };
202
206
  }
203
207
  const SourceCache = new WeakMap();
204
208
  function asSource(source) {
@@ -843,7 +847,7 @@ class CompletionDialog {
843
847
  }, prev ? prev.timestamp : Date.now(), selected, false);
844
848
  }
845
849
  map(changes) {
846
- 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);
850
+ return new CompletionDialog(this.options, this.attrs, { ...this.tooltip, pos: changes.mapPos(this.tooltip.pos) }, this.timestamp, this.selected, this.disabled);
847
851
  }
848
852
  setDisabled() {
849
853
  return new CompletionDialog(this.options, this.attrs, this.tooltip, this.timestamp, this.selected, true);
@@ -1028,7 +1032,10 @@ function applyCompletion(view, option) {
1028
1032
  if (!(result instanceof ActiveResult))
1029
1033
  return false;
1030
1034
  if (typeof apply == "string")
1031
- view.dispatch(Object.assign(Object.assign({}, insertCompletionText(view.state, apply, result.from, result.to)), { annotations: pickedCompletion.of(option.completion) }));
1035
+ view.dispatch({
1036
+ ...insertCompletionText(view.state, apply, result.from, result.to),
1037
+ annotations: pickedCompletion.of(option.completion)
1038
+ });
1032
1039
  else
1033
1040
  apply(view, option.completion, result.from, result.to);
1034
1041
  return true;
@@ -1445,7 +1452,7 @@ class Snippet {
1445
1452
  let fields = [];
1446
1453
  let lines = [], positions = [], m;
1447
1454
  for (let line of template.split(/\r\n?|\n/)) {
1448
- while (m = /[#$]\{(?:(\d+)(?::([^}]*))?|((?:\\[{}]|[^}])*))\}/.exec(line)) {
1455
+ while (m = /[#$]\{(?:(\d+)(?::([^{}]*))?|((?:\\[{}]|[^{}])*))\}/.exec(line)) {
1449
1456
  let seq = m[1] ? +m[1] : null, rawName = m[2] || m[3] || "", found = -1;
1450
1457
  let name = rawName.replace(/\\[{}]/g, m => m[1]);
1451
1458
  for (let i = 0; i < fields.length; i++) {
@@ -1462,6 +1469,12 @@ class Snippet {
1462
1469
  if (pos.field >= found)
1463
1470
  pos.field++;
1464
1471
  }
1472
+ for (let pos of positions)
1473
+ if (pos.line == lines.length && pos.from > m.index) {
1474
+ let snip = m[2] ? 3 + (m[1] || "").length : 2;
1475
+ pos.from -= snip;
1476
+ pos.to -= snip;
1477
+ }
1465
1478
  positions.push(new FieldPos(found, lines.length, m.index, m.index + name.length));
1466
1479
  line = line.slice(0, m.index) + rawName + line.slice(m.index + m[0].length);
1467
1480
  }
@@ -1491,7 +1504,7 @@ class ActiveSnippet {
1491
1504
  constructor(ranges, active) {
1492
1505
  this.ranges = ranges;
1493
1506
  this.active = active;
1494
- this.deco = view.Decoration.set(ranges.map(r => (r.from == r.to ? fieldMarker : fieldRange).range(r.from, r.to)));
1507
+ this.deco = view.Decoration.set(ranges.map(r => (r.from == r.to ? fieldMarker : fieldRange).range(r.from, r.to)), true);
1495
1508
  }
1496
1509
  map(changes) {
1497
1510
  let ranges = [];
@@ -1651,7 +1664,7 @@ properties from `completion`, plus an `apply` function that
1651
1664
  applies the snippet.
1652
1665
  */
1653
1666
  function snippetCompletion(template, completion) {
1654
- return Object.assign(Object.assign({}, completion), { apply: snippet(template) });
1667
+ return { ...completion, apply: snippet(template) };
1655
1668
  }
1656
1669
  const snippetPointerHandler = view.EditorView.domEventHandlers({
1657
1670
  mousedown(event, view) {
@@ -1787,7 +1800,7 @@ that bracket.
1787
1800
  function closeBrackets() {
1788
1801
  return [inputHandler, bracketState];
1789
1802
  }
1790
- const definedClosing = "()[]{}<>";
1803
+ const definedClosing = "()[]{}<>«»»«[]{}";
1791
1804
  function closing(ch) {
1792
1805
  for (let i = 0; i < definedClosing.length; i += 2)
1793
1806
  if (definedClosing.charCodeAt(i) == ch)
@@ -2009,17 +2022,18 @@ function autocompletion(config = {}) {
2009
2022
  /**
2010
2023
  Basic keybindings for autocompletion.
2011
2024
 
2012
- - Ctrl-Space (and Alt-\` on macOS): [`startCompletion`](https://codemirror.net/6/docs/ref/#autocomplete.startCompletion)
2025
+ - Ctrl-Space (and Alt-\` or Alt-i on macOS): [`startCompletion`](https://codemirror.net/6/docs/ref/#autocomplete.startCompletion)
2013
2026
  - Escape: [`closeCompletion`](https://codemirror.net/6/docs/ref/#autocomplete.closeCompletion)
2014
2027
  - ArrowDown: [`moveCompletionSelection`](https://codemirror.net/6/docs/ref/#autocomplete.moveCompletionSelection)`(true)`
2015
2028
  - ArrowUp: [`moveCompletionSelection`](https://codemirror.net/6/docs/ref/#autocomplete.moveCompletionSelection)`(false)`
2016
2029
  - PageDown: [`moveCompletionSelection`](https://codemirror.net/6/docs/ref/#autocomplete.moveCompletionSelection)`(true, "page")`
2017
- - PageDown: [`moveCompletionSelection`](https://codemirror.net/6/docs/ref/#autocomplete.moveCompletionSelection)`(true, "page")`
2030
+ - PageUp: [`moveCompletionSelection`](https://codemirror.net/6/docs/ref/#autocomplete.moveCompletionSelection)`(false, "page")`
2018
2031
  - Enter: [`acceptCompletion`](https://codemirror.net/6/docs/ref/#autocomplete.acceptCompletion)
2019
2032
  */
2020
2033
  const completionKeymap = [
2021
2034
  { key: "Ctrl-Space", run: startCompletion },
2022
2035
  { mac: "Alt-`", run: startCompletion },
2036
+ { mac: "Alt-i", run: startCompletion },
2023
2037
  { key: "Escape", run: closeCompletion },
2024
2038
  { key: "ArrowDown", run: moveCompletionSelection(true) },
2025
2039
  { key: "ArrowUp", run: moveCompletionSelection(false) },
package/dist/index.d.cts CHANGED
@@ -601,12 +601,12 @@ declare function autocompletion(config?: CompletionConfig): Extension;
601
601
  /**
602
602
  Basic keybindings for autocompletion.
603
603
 
604
- - Ctrl-Space (and Alt-\` on macOS): [`startCompletion`](https://codemirror.net/6/docs/ref/#autocomplete.startCompletion)
604
+ - Ctrl-Space (and Alt-\` or Alt-i on macOS): [`startCompletion`](https://codemirror.net/6/docs/ref/#autocomplete.startCompletion)
605
605
  - Escape: [`closeCompletion`](https://codemirror.net/6/docs/ref/#autocomplete.closeCompletion)
606
606
  - ArrowDown: [`moveCompletionSelection`](https://codemirror.net/6/docs/ref/#autocomplete.moveCompletionSelection)`(true)`
607
607
  - ArrowUp: [`moveCompletionSelection`](https://codemirror.net/6/docs/ref/#autocomplete.moveCompletionSelection)`(false)`
608
608
  - PageDown: [`moveCompletionSelection`](https://codemirror.net/6/docs/ref/#autocomplete.moveCompletionSelection)`(true, "page")`
609
- - PageDown: [`moveCompletionSelection`](https://codemirror.net/6/docs/ref/#autocomplete.moveCompletionSelection)`(true, "page")`
609
+ - PageUp: [`moveCompletionSelection`](https://codemirror.net/6/docs/ref/#autocomplete.moveCompletionSelection)`(false, "page")`
610
610
  - Enter: [`acceptCompletion`](https://codemirror.net/6/docs/ref/#autocomplete.acceptCompletion)
611
611
  */
612
612
  declare const completionKeymap: readonly KeyBinding[];
package/dist/index.d.ts CHANGED
@@ -601,12 +601,12 @@ declare function autocompletion(config?: CompletionConfig): Extension;
601
601
  /**
602
602
  Basic keybindings for autocompletion.
603
603
 
604
- - Ctrl-Space (and Alt-\` on macOS): [`startCompletion`](https://codemirror.net/6/docs/ref/#autocomplete.startCompletion)
604
+ - Ctrl-Space (and Alt-\` or Alt-i on macOS): [`startCompletion`](https://codemirror.net/6/docs/ref/#autocomplete.startCompletion)
605
605
  - Escape: [`closeCompletion`](https://codemirror.net/6/docs/ref/#autocomplete.closeCompletion)
606
606
  - ArrowDown: [`moveCompletionSelection`](https://codemirror.net/6/docs/ref/#autocomplete.moveCompletionSelection)`(true)`
607
607
  - ArrowUp: [`moveCompletionSelection`](https://codemirror.net/6/docs/ref/#autocomplete.moveCompletionSelection)`(false)`
608
608
  - PageDown: [`moveCompletionSelection`](https://codemirror.net/6/docs/ref/#autocomplete.moveCompletionSelection)`(true, "page")`
609
- - PageDown: [`moveCompletionSelection`](https://codemirror.net/6/docs/ref/#autocomplete.moveCompletionSelection)`(true, "page")`
609
+ - PageUp: [`moveCompletionSelection`](https://codemirror.net/6/docs/ref/#autocomplete.moveCompletionSelection)`(false, "page")`
610
610
  - Enter: [`acceptCompletion`](https://codemirror.net/6/docs/ref/#autocomplete.acceptCompletion)
611
611
  */
612
612
  declare const completionKeymap: readonly KeyBinding[];
package/dist/index.js CHANGED
@@ -187,16 +187,20 @@ selection range that has the same text in front of it.
187
187
  */
188
188
  function insertCompletionText(state, text, from, to) {
189
189
  let { main } = state.selection, fromOff = from - main.from, toOff = to - main.from;
190
- return Object.assign(Object.assign({}, state.changeByRange(range => {
191
- if (range != main && from != to &&
192
- state.sliceDoc(range.from + fromOff, range.from + toOff) != state.sliceDoc(from, to))
193
- return { range };
194
- let lines = state.toText(text);
195
- return {
196
- changes: { from: range.from + fromOff, to: to == main.from ? range.to : range.from + toOff, insert: lines },
197
- range: EditorSelection.cursor(range.from + fromOff + lines.length)
198
- };
199
- })), { scrollIntoView: true, userEvent: "input.complete" });
190
+ return {
191
+ ...state.changeByRange(range => {
192
+ if (range != main && from != to &&
193
+ state.sliceDoc(range.from + fromOff, range.from + toOff) != state.sliceDoc(from, to))
194
+ return { range };
195
+ let lines = state.toText(text);
196
+ return {
197
+ changes: { from: range.from + fromOff, to: to == main.from ? range.to : range.from + toOff, insert: lines },
198
+ range: EditorSelection.cursor(range.from + fromOff + lines.length)
199
+ };
200
+ }),
201
+ scrollIntoView: true,
202
+ userEvent: "input.complete"
203
+ };
200
204
  }
201
205
  const SourceCache = /*@__PURE__*/new WeakMap();
202
206
  function asSource(source) {
@@ -841,7 +845,7 @@ class CompletionDialog {
841
845
  }, prev ? prev.timestamp : Date.now(), selected, false);
842
846
  }
843
847
  map(changes) {
844
- 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);
848
+ return new CompletionDialog(this.options, this.attrs, { ...this.tooltip, pos: changes.mapPos(this.tooltip.pos) }, this.timestamp, this.selected, this.disabled);
845
849
  }
846
850
  setDisabled() {
847
851
  return new CompletionDialog(this.options, this.attrs, this.tooltip, this.timestamp, this.selected, true);
@@ -1026,7 +1030,10 @@ function applyCompletion(view, option) {
1026
1030
  if (!(result instanceof ActiveResult))
1027
1031
  return false;
1028
1032
  if (typeof apply == "string")
1029
- view.dispatch(Object.assign(Object.assign({}, insertCompletionText(view.state, apply, result.from, result.to)), { annotations: pickedCompletion.of(option.completion) }));
1033
+ view.dispatch({
1034
+ ...insertCompletionText(view.state, apply, result.from, result.to),
1035
+ annotations: pickedCompletion.of(option.completion)
1036
+ });
1030
1037
  else
1031
1038
  apply(view, option.completion, result.from, result.to);
1032
1039
  return true;
@@ -1443,7 +1450,7 @@ class Snippet {
1443
1450
  let fields = [];
1444
1451
  let lines = [], positions = [], m;
1445
1452
  for (let line of template.split(/\r\n?|\n/)) {
1446
- while (m = /[#$]\{(?:(\d+)(?::([^}]*))?|((?:\\[{}]|[^}])*))\}/.exec(line)) {
1453
+ while (m = /[#$]\{(?:(\d+)(?::([^{}]*))?|((?:\\[{}]|[^{}])*))\}/.exec(line)) {
1447
1454
  let seq = m[1] ? +m[1] : null, rawName = m[2] || m[3] || "", found = -1;
1448
1455
  let name = rawName.replace(/\\[{}]/g, m => m[1]);
1449
1456
  for (let i = 0; i < fields.length; i++) {
@@ -1460,6 +1467,12 @@ class Snippet {
1460
1467
  if (pos.field >= found)
1461
1468
  pos.field++;
1462
1469
  }
1470
+ for (let pos of positions)
1471
+ if (pos.line == lines.length && pos.from > m.index) {
1472
+ let snip = m[2] ? 3 + (m[1] || "").length : 2;
1473
+ pos.from -= snip;
1474
+ pos.to -= snip;
1475
+ }
1463
1476
  positions.push(new FieldPos(found, lines.length, m.index, m.index + name.length));
1464
1477
  line = line.slice(0, m.index) + rawName + line.slice(m.index + m[0].length);
1465
1478
  }
@@ -1489,7 +1502,7 @@ class ActiveSnippet {
1489
1502
  constructor(ranges, active) {
1490
1503
  this.ranges = ranges;
1491
1504
  this.active = active;
1492
- this.deco = Decoration.set(ranges.map(r => (r.from == r.to ? fieldMarker : fieldRange).range(r.from, r.to)));
1505
+ this.deco = Decoration.set(ranges.map(r => (r.from == r.to ? fieldMarker : fieldRange).range(r.from, r.to)), true);
1493
1506
  }
1494
1507
  map(changes) {
1495
1508
  let ranges = [];
@@ -1649,7 +1662,7 @@ properties from `completion`, plus an `apply` function that
1649
1662
  applies the snippet.
1650
1663
  */
1651
1664
  function snippetCompletion(template, completion) {
1652
- return Object.assign(Object.assign({}, completion), { apply: snippet(template) });
1665
+ return { ...completion, apply: snippet(template) };
1653
1666
  }
1654
1667
  const snippetPointerHandler = /*@__PURE__*/EditorView.domEventHandlers({
1655
1668
  mousedown(event, view) {
@@ -1785,7 +1798,7 @@ that bracket.
1785
1798
  function closeBrackets() {
1786
1799
  return [inputHandler, bracketState];
1787
1800
  }
1788
- const definedClosing = "()[]{}<>";
1801
+ const definedClosing = "()[]{}<>«»»«[]{}";
1789
1802
  function closing(ch) {
1790
1803
  for (let i = 0; i < definedClosing.length; i += 2)
1791
1804
  if (definedClosing.charCodeAt(i) == ch)
@@ -2007,17 +2020,18 @@ function autocompletion(config = {}) {
2007
2020
  /**
2008
2021
  Basic keybindings for autocompletion.
2009
2022
 
2010
- - Ctrl-Space (and Alt-\` on macOS): [`startCompletion`](https://codemirror.net/6/docs/ref/#autocomplete.startCompletion)
2023
+ - Ctrl-Space (and Alt-\` or Alt-i on macOS): [`startCompletion`](https://codemirror.net/6/docs/ref/#autocomplete.startCompletion)
2011
2024
  - Escape: [`closeCompletion`](https://codemirror.net/6/docs/ref/#autocomplete.closeCompletion)
2012
2025
  - ArrowDown: [`moveCompletionSelection`](https://codemirror.net/6/docs/ref/#autocomplete.moveCompletionSelection)`(true)`
2013
2026
  - ArrowUp: [`moveCompletionSelection`](https://codemirror.net/6/docs/ref/#autocomplete.moveCompletionSelection)`(false)`
2014
2027
  - PageDown: [`moveCompletionSelection`](https://codemirror.net/6/docs/ref/#autocomplete.moveCompletionSelection)`(true, "page")`
2015
- - PageDown: [`moveCompletionSelection`](https://codemirror.net/6/docs/ref/#autocomplete.moveCompletionSelection)`(true, "page")`
2028
+ - PageUp: [`moveCompletionSelection`](https://codemirror.net/6/docs/ref/#autocomplete.moveCompletionSelection)`(false, "page")`
2016
2029
  - Enter: [`acceptCompletion`](https://codemirror.net/6/docs/ref/#autocomplete.acceptCompletion)
2017
2030
  */
2018
2031
  const completionKeymap = [
2019
2032
  { key: "Ctrl-Space", run: startCompletion },
2020
2033
  { mac: "Alt-`", run: startCompletion },
2034
+ { mac: "Alt-i", run: startCompletion },
2021
2035
  { key: "Escape", run: closeCompletion },
2022
2036
  { key: "ArrowDown", run: /*@__PURE__*/moveCompletionSelection(true) },
2023
2037
  { key: "ArrowUp", run: /*@__PURE__*/moveCompletionSelection(false) },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemirror/autocomplete",
3
- "version": "6.18.5",
3
+ "version": "6.18.7",
4
4
  "description": "Autocompletion for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",