@codemirror/autocomplete 6.10.2 → 6.11.1

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,19 @@
1
+ ## 6.11.1 (2023-11-27)
2
+
3
+ ### Bug fixes
4
+
5
+ Fix a bug that caused typing over closed brackets after pressing enter to still not work in many situations.
6
+
7
+ ## 6.11.0 (2023-11-09)
8
+
9
+ ### Bug fixes
10
+
11
+ Fix an issue that would prevent typing over closed brackets after starting a new line with enter.
12
+
13
+ ### New features
14
+
15
+ Additional elements rendered in completion options with `addToOptions` are now given access to the editor view.
16
+
1
17
  ## 6.10.2 (2023-10-13)
2
18
 
3
19
  ### Bug fixes
package/dist/index.cjs CHANGED
@@ -404,7 +404,7 @@ function optionContent(config) {
404
404
  position: 20
405
405
  });
406
406
  content.push({
407
- render(completion, _s, match) {
407
+ render(completion, _s, _v, match) {
408
408
  let labelElt = document.createElement("span");
409
409
  labelElt.className = "cm-completionLabel";
410
410
  let label = completion.displayLabel || completion.label, off = 0;
@@ -653,7 +653,7 @@ class CompletionTooltip {
653
653
  if (cls)
654
654
  li.className = cls;
655
655
  for (let source of this.optionContent) {
656
- let node = source(completion, this.view.state, match);
656
+ let node = source(completion, this.view.state, this.view, match);
657
657
  if (node)
658
658
  li.appendChild(node);
659
659
  }
@@ -1662,13 +1662,11 @@ closedBracket.endSide = -1;
1662
1662
  const bracketState = state.StateField.define({
1663
1663
  create() { return state.RangeSet.empty; },
1664
1664
  update(value, tr) {
1665
+ value = value.map(tr.changes);
1665
1666
  if (tr.selection) {
1666
- let lineStart = tr.state.doc.lineAt(tr.selection.main.head).from;
1667
- let prevLineStart = tr.startState.doc.lineAt(tr.startState.selection.main.head).from;
1668
- if (lineStart != tr.changes.mapPos(prevLineStart, -1))
1669
- value = state.RangeSet.empty;
1667
+ let line = tr.state.doc.lineAt(tr.selection.main.head);
1668
+ value = value.update({ filter: from => from >= line.from && from <= line.to });
1670
1669
  }
1671
- value = value.map(tr.changes);
1672
1670
  for (let effect of tr.effects)
1673
1671
  if (effect.is(closeBracketEffect))
1674
1672
  value = value.update({ add: [closedBracket.range(effect.value, effect.value + 1)] });
package/dist/index.d.cts CHANGED
@@ -340,7 +340,7 @@ interface CompletionConfig {
340
340
  80.
341
341
  */
342
342
  addToOptions?: {
343
- render: (completion: Completion, state: EditorState) => Node | null;
343
+ render: (completion: Completion, state: EditorState, view: EditorView) => Node | null;
344
344
  position: number;
345
345
  }[];
346
346
  /**
package/dist/index.d.ts CHANGED
@@ -340,7 +340,7 @@ interface CompletionConfig {
340
340
  80.
341
341
  */
342
342
  addToOptions?: {
343
- render: (completion: Completion, state: EditorState) => Node | null;
343
+ render: (completion: Completion, state: EditorState, view: EditorView) => Node | null;
344
344
  position: number;
345
345
  }[];
346
346
  /**
package/dist/index.js CHANGED
@@ -402,7 +402,7 @@ function optionContent(config) {
402
402
  position: 20
403
403
  });
404
404
  content.push({
405
- render(completion, _s, match) {
405
+ render(completion, _s, _v, match) {
406
406
  let labelElt = document.createElement("span");
407
407
  labelElt.className = "cm-completionLabel";
408
408
  let label = completion.displayLabel || completion.label, off = 0;
@@ -651,7 +651,7 @@ class CompletionTooltip {
651
651
  if (cls)
652
652
  li.className = cls;
653
653
  for (let source of this.optionContent) {
654
- let node = source(completion, this.view.state, match);
654
+ let node = source(completion, this.view.state, this.view, match);
655
655
  if (node)
656
656
  li.appendChild(node);
657
657
  }
@@ -1660,13 +1660,11 @@ closedBracket.endSide = -1;
1660
1660
  const bracketState = /*@__PURE__*/StateField.define({
1661
1661
  create() { return RangeSet.empty; },
1662
1662
  update(value, tr) {
1663
+ value = value.map(tr.changes);
1663
1664
  if (tr.selection) {
1664
- let lineStart = tr.state.doc.lineAt(tr.selection.main.head).from;
1665
- let prevLineStart = tr.startState.doc.lineAt(tr.startState.selection.main.head).from;
1666
- if (lineStart != tr.changes.mapPos(prevLineStart, -1))
1667
- value = RangeSet.empty;
1665
+ let line = tr.state.doc.lineAt(tr.selection.main.head);
1666
+ value = value.update({ filter: from => from >= line.from && from <= line.to });
1668
1667
  }
1669
- value = value.map(tr.changes);
1670
1668
  for (let effect of tr.effects)
1671
1669
  if (effect.is(closeBracketEffect))
1672
1670
  value = value.update({ add: [closedBracket.range(effect.value, effect.value + 1)] });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemirror/autocomplete",
3
- "version": "6.10.2",
3
+ "version": "6.11.1",
4
4
  "description": "Autocompletion for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",