@codemirror/autocomplete 0.19.13 → 0.19.14

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,9 @@
1
+ ## 0.19.14 (2022-03-10)
2
+
3
+ ### Bug fixes
4
+
5
+ Make the ARIA attributes added to the editor during autocompletion spec-compliant.
6
+
1
7
  ## 0.19.13 (2022-02-18)
2
8
 
3
9
  ### Bug fixes
package/dist/index.cjs CHANGED
@@ -514,6 +514,7 @@ class CompletionTooltip {
514
514
  const ul = document.createElement("ul");
515
515
  ul.id = id;
516
516
  ul.setAttribute("role", "listbox");
517
+ ul.setAttribute("aria-expanded", "true");
517
518
  for (let i = range.from; i < range.to; i++) {
518
519
  let { completion, match } = options[i];
519
520
  const li = ul.appendChild(document.createElement("li"));
@@ -574,7 +575,6 @@ function sortOptions(active, state) {
574
575
  }
575
576
  }
576
577
  }
577
- options.sort(cmpOption);
578
578
  let result = [], prev = null;
579
579
  for (let opt of options.sort(cmpOption)) {
580
580
  if (result.length == MaxOptions)
@@ -607,10 +607,11 @@ class CompletionDialog {
607
607
  let selected = 0;
608
608
  if (prev && prev.selected) {
609
609
  let selectedValue = prev.options[prev.selected].completion;
610
- for (let i = 0; i < options.length && !selected; i++) {
611
- if (options[i].completion == selectedValue)
610
+ for (let i = 0; i < options.length; i++)
611
+ if (options[i].completion == selectedValue) {
612
612
  selected = i;
613
- }
613
+ break;
614
+ }
614
615
  }
615
616
  return new CompletionDialog(options, makeAttrs(id, selected), {
616
617
  pos: active.reduce((a, b) => b.hasResult() ? Math.min(a, b.from) : a, 1e8),
@@ -671,13 +672,12 @@ function sameResults(a, b) {
671
672
  }
672
673
  }
673
674
  const baseAttrs = {
674
- "aria-autocomplete": "list",
675
- "aria-expanded": "false"
675
+ "aria-autocomplete": "list"
676
676
  };
677
677
  function makeAttrs(id, selected) {
678
678
  return {
679
679
  "aria-autocomplete": "list",
680
- "aria-expanded": "true",
680
+ "aria-haspopup": "listbox",
681
681
  "aria-activedescendant": id + "-" + selected,
682
682
  "aria-controls": id
683
683
  };
@@ -859,7 +859,7 @@ const completionPlugin = view.ViewPlugin.fromClass(class {
859
859
  for (let i = 0; i < this.running.length; i++) {
860
860
  let query = this.running[i];
861
861
  if (doesReset ||
862
- query.updates.length + update.transactions.length > MaxUpdateCount && query.time - Date.now() > MinAbortTime) {
862
+ query.updates.length + update.transactions.length > MaxUpdateCount && Date.now() - query.time > MinAbortTime) {
863
863
  for (let handler of query.context.abortListeners) {
864
864
  try {
865
865
  handler();
package/dist/index.js CHANGED
@@ -510,6 +510,7 @@ class CompletionTooltip {
510
510
  const ul = document.createElement("ul");
511
511
  ul.id = id;
512
512
  ul.setAttribute("role", "listbox");
513
+ ul.setAttribute("aria-expanded", "true");
513
514
  for (let i = range.from; i < range.to; i++) {
514
515
  let { completion, match } = options[i];
515
516
  const li = ul.appendChild(document.createElement("li"));
@@ -570,7 +571,6 @@ function sortOptions(active, state) {
570
571
  }
571
572
  }
572
573
  }
573
- options.sort(cmpOption);
574
574
  let result = [], prev = null;
575
575
  for (let opt of options.sort(cmpOption)) {
576
576
  if (result.length == MaxOptions)
@@ -603,10 +603,11 @@ class CompletionDialog {
603
603
  let selected = 0;
604
604
  if (prev && prev.selected) {
605
605
  let selectedValue = prev.options[prev.selected].completion;
606
- for (let i = 0; i < options.length && !selected; i++) {
607
- if (options[i].completion == selectedValue)
606
+ for (let i = 0; i < options.length; i++)
607
+ if (options[i].completion == selectedValue) {
608
608
  selected = i;
609
- }
609
+ break;
610
+ }
610
611
  }
611
612
  return new CompletionDialog(options, makeAttrs(id, selected), {
612
613
  pos: active.reduce((a, b) => b.hasResult() ? Math.min(a, b.from) : a, 1e8),
@@ -667,13 +668,12 @@ function sameResults(a, b) {
667
668
  }
668
669
  }
669
670
  const baseAttrs = {
670
- "aria-autocomplete": "list",
671
- "aria-expanded": "false"
671
+ "aria-autocomplete": "list"
672
672
  };
673
673
  function makeAttrs(id, selected) {
674
674
  return {
675
675
  "aria-autocomplete": "list",
676
- "aria-expanded": "true",
676
+ "aria-haspopup": "listbox",
677
677
  "aria-activedescendant": id + "-" + selected,
678
678
  "aria-controls": id
679
679
  };
@@ -855,7 +855,7 @@ const completionPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
855
855
  for (let i = 0; i < this.running.length; i++) {
856
856
  let query = this.running[i];
857
857
  if (doesReset ||
858
- query.updates.length + update.transactions.length > MaxUpdateCount && query.time - Date.now() > MinAbortTime) {
858
+ query.updates.length + update.transactions.length > MaxUpdateCount && Date.now() - query.time > MinAbortTime) {
859
859
  for (let handler of query.context.abortListeners) {
860
860
  try {
861
861
  handler();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemirror/autocomplete",
3
- "version": "0.19.13",
3
+ "version": "0.19.14",
4
4
  "description": "Autocompletion for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",