@codemirror/autocomplete 6.19.0 → 6.20.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,15 @@
1
+ ## 6.20.0 (2025-11-20)
2
+
3
+ ### New features
4
+
5
+ Completions now support a `sortText` property to influence sort order.
6
+
7
+ ## 6.19.1 (2025-10-23)
8
+
9
+ ### Bug fixes
10
+
11
+ Make sure a completion's info panel is associated with that completion in the accessibility tree.
12
+
1
13
  ## 6.19.0 (2025-09-26)
2
14
 
3
15
  ### New features
package/dist/index.cjs CHANGED
@@ -391,7 +391,7 @@ const completionConfig = state.Facet.define({
391
391
  addToOptions: [],
392
392
  positionInfo: defaultPositionInfo,
393
393
  filterStrict: false,
394
- compareCompletions: (a, b) => a.label.localeCompare(b.label),
394
+ compareCompletions: (a, b) => (a.sortText || a.label).localeCompare(b.sortText || b.label),
395
395
  interactionDelay: 75,
396
396
  updateSyncTime: 100
397
397
  }, {
@@ -590,7 +590,8 @@ class CompletionTooltip {
590
590
  this.range = rangeAroundSelected(open.options.length, open.selected, this.view.state.facet(completionConfig).maxRenderedOptions);
591
591
  this.showOptions(open.options, cState.id);
592
592
  }
593
- if (this.updateSelectedOption(open.selected)) {
593
+ let newSel = this.updateSelectedOption(open.selected);
594
+ if (newSel) {
594
595
  this.destroyInfo();
595
596
  let { completion } = open.options[open.selected];
596
597
  let { info } = completion;
@@ -607,6 +608,7 @@ class CompletionTooltip {
607
608
  }
608
609
  else {
609
610
  this.addInfoPane(infoResult, completion);
611
+ newSel.setAttribute("aria-describedby", this.info.id);
610
612
  }
611
613
  }
612
614
  }
@@ -614,6 +616,7 @@ class CompletionTooltip {
614
616
  this.destroyInfo();
615
617
  let wrap = this.info = document.createElement("div");
616
618
  wrap.className = "cm-tooltip cm-completionInfo";
619
+ wrap.id = "cm-completionInfo-" + Math.floor(Math.random() * 0xffff).toString(16);
617
620
  if (content.nodeType != null) {
618
621
  wrap.appendChild(content);
619
622
  this.infoDestroy = null;
@@ -639,8 +642,10 @@ class CompletionTooltip {
639
642
  }
640
643
  }
641
644
  else {
642
- if (opt.hasAttribute("aria-selected"))
645
+ if (opt.hasAttribute("aria-selected")) {
643
646
  opt.removeAttribute("aria-selected");
647
+ opt.removeAttribute("aria-describedby");
648
+ }
644
649
  }
645
650
  }
646
651
  if (set)
package/dist/index.d.cts CHANGED
@@ -21,6 +21,11 @@ interface Completion {
21
21
  */
22
22
  displayLabel?: string;
23
23
  /**
24
+ Overrides the text that is used to sort completions. Will
25
+ default to `label` if not given.
26
+ */
27
+ sortText?: string;
28
+ /**
24
29
  An optional short piece of information to show (with a different
25
30
  style) after the label.
26
31
  */
package/dist/index.d.ts CHANGED
@@ -21,6 +21,11 @@ interface Completion {
21
21
  */
22
22
  displayLabel?: string;
23
23
  /**
24
+ Overrides the text that is used to sort completions. Will
25
+ default to `label` if not given.
26
+ */
27
+ sortText?: string;
28
+ /**
24
29
  An optional short piece of information to show (with a different
25
30
  style) after the label.
26
31
  */
package/dist/index.js CHANGED
@@ -389,7 +389,7 @@ const completionConfig = /*@__PURE__*/Facet.define({
389
389
  addToOptions: [],
390
390
  positionInfo: defaultPositionInfo,
391
391
  filterStrict: false,
392
- compareCompletions: (a, b) => a.label.localeCompare(b.label),
392
+ compareCompletions: (a, b) => (a.sortText || a.label).localeCompare(b.sortText || b.label),
393
393
  interactionDelay: 75,
394
394
  updateSyncTime: 100
395
395
  }, {
@@ -588,7 +588,8 @@ class CompletionTooltip {
588
588
  this.range = rangeAroundSelected(open.options.length, open.selected, this.view.state.facet(completionConfig).maxRenderedOptions);
589
589
  this.showOptions(open.options, cState.id);
590
590
  }
591
- if (this.updateSelectedOption(open.selected)) {
591
+ let newSel = this.updateSelectedOption(open.selected);
592
+ if (newSel) {
592
593
  this.destroyInfo();
593
594
  let { completion } = open.options[open.selected];
594
595
  let { info } = completion;
@@ -605,6 +606,7 @@ class CompletionTooltip {
605
606
  }
606
607
  else {
607
608
  this.addInfoPane(infoResult, completion);
609
+ newSel.setAttribute("aria-describedby", this.info.id);
608
610
  }
609
611
  }
610
612
  }
@@ -612,6 +614,7 @@ class CompletionTooltip {
612
614
  this.destroyInfo();
613
615
  let wrap = this.info = document.createElement("div");
614
616
  wrap.className = "cm-tooltip cm-completionInfo";
617
+ wrap.id = "cm-completionInfo-" + Math.floor(Math.random() * 0xffff).toString(16);
615
618
  if (content.nodeType != null) {
616
619
  wrap.appendChild(content);
617
620
  this.infoDestroy = null;
@@ -637,8 +640,10 @@ class CompletionTooltip {
637
640
  }
638
641
  }
639
642
  else {
640
- if (opt.hasAttribute("aria-selected"))
643
+ if (opt.hasAttribute("aria-selected")) {
641
644
  opt.removeAttribute("aria-selected");
645
+ opt.removeAttribute("aria-describedby");
646
+ }
642
647
  }
643
648
  }
644
649
  if (set)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemirror/autocomplete",
3
- "version": "6.19.0",
3
+ "version": "6.20.0",
4
4
  "description": "Autocompletion for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",