@codemirror/autocomplete 6.3.0 → 6.3.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 +10 -0
- package/dist/index.cjs +49 -23
- package/dist/index.js +49 -23
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
## 6.3.1 (2022-11-14)
|
|
2
|
+
|
|
3
|
+
### Bug fixes
|
|
4
|
+
|
|
5
|
+
Fix a regression where transactions for picking a completion (without custom `apply` method) no longer had the `pickedCompletion` annotation.
|
|
6
|
+
|
|
7
|
+
Reduce flickering for completion sources without `validFor` info by temporarily showing a disabled tooltip while the completion updates.
|
|
8
|
+
|
|
9
|
+
Make sure completion info tooltips are kept within the space provided by the `tooltipSpace` option.
|
|
10
|
+
|
|
1
11
|
## 6.3.0 (2022-09-22)
|
|
2
12
|
|
|
3
13
|
### New features
|
package/dist/index.cjs
CHANGED
|
@@ -179,7 +179,7 @@ function applyCompletion(view, option) {
|
|
|
179
179
|
const apply = option.completion.apply || option.completion.label;
|
|
180
180
|
let result = option.source;
|
|
181
181
|
if (typeof apply == "string")
|
|
182
|
-
view.dispatch(insertCompletionText(view.state, apply, result.from, result.to));
|
|
182
|
+
view.dispatch(Object.assign(Object.assign({}, insertCompletionText(view.state, apply, result.from, result.to)), { annotations: pickedCompletion.of(option.completion) }));
|
|
183
183
|
else
|
|
184
184
|
apply(view, option.completion, result.from, result.to);
|
|
185
185
|
}
|
|
@@ -414,6 +414,7 @@ class CompletionTooltip {
|
|
|
414
414
|
write: (pos) => this.positionInfo(pos),
|
|
415
415
|
key: this
|
|
416
416
|
};
|
|
417
|
+
this.space = null;
|
|
417
418
|
let cState = view.state.field(stateField);
|
|
418
419
|
let { options, selected } = cState.open;
|
|
419
420
|
let config = view.state.facet(completionConfig);
|
|
@@ -439,10 +440,17 @@ class CompletionTooltip {
|
|
|
439
440
|
}
|
|
440
441
|
mount() { this.updateSel(); }
|
|
441
442
|
update(update) {
|
|
442
|
-
|
|
443
|
+
var _a, _b, _c;
|
|
444
|
+
let cState = update.state.field(this.stateField);
|
|
445
|
+
let prevState = update.startState.field(this.stateField);
|
|
446
|
+
if (cState != prevState) {
|
|
443
447
|
this.updateSel();
|
|
448
|
+
if (((_a = cState.open) === null || _a === void 0 ? void 0 : _a.disabled) != ((_b = prevState.open) === null || _b === void 0 ? void 0 : _b.disabled))
|
|
449
|
+
this.dom.classList.toggle("cm-tooltip-autocomplete-disabled", !!((_c = cState.open) === null || _c === void 0 ? void 0 : _c.disabled));
|
|
450
|
+
}
|
|
444
451
|
}
|
|
445
|
-
positioned() {
|
|
452
|
+
positioned(space) {
|
|
453
|
+
this.space = space;
|
|
446
454
|
if (this.info)
|
|
447
455
|
this.view.requestMeasure(this.placeInfo);
|
|
448
456
|
}
|
|
@@ -509,27 +517,32 @@ class CompletionTooltip {
|
|
|
509
517
|
let sel = this.dom.querySelector("[aria-selected]");
|
|
510
518
|
if (!sel || !this.info)
|
|
511
519
|
return null;
|
|
512
|
-
let win = this.dom.ownerDocument.defaultView || window;
|
|
513
520
|
let listRect = this.dom.getBoundingClientRect();
|
|
514
521
|
let infoRect = this.info.getBoundingClientRect();
|
|
515
522
|
let selRect = sel.getBoundingClientRect();
|
|
516
|
-
|
|
523
|
+
let space = this.space;
|
|
524
|
+
if (!space) {
|
|
525
|
+
let win = this.dom.ownerDocument.defaultView || window;
|
|
526
|
+
space = { left: 0, top: 0, right: win.innerWidth, bottom: win.innerHeight };
|
|
527
|
+
}
|
|
528
|
+
if (selRect.top > Math.min(space.bottom, listRect.bottom) - 10 ||
|
|
529
|
+
selRect.bottom < Math.max(space.top, listRect.top) + 10)
|
|
517
530
|
return null;
|
|
518
531
|
let rtl = this.view.textDirection == view.Direction.RTL, left = rtl, narrow = false, maxWidth;
|
|
519
532
|
let top = "", bottom = "";
|
|
520
|
-
let spaceLeft = listRect.left, spaceRight =
|
|
533
|
+
let spaceLeft = listRect.left - space.left, spaceRight = space.right - listRect.right;
|
|
521
534
|
if (left && spaceLeft < Math.min(infoRect.width, spaceRight))
|
|
522
535
|
left = false;
|
|
523
536
|
else if (!left && spaceRight < Math.min(infoRect.width, spaceLeft))
|
|
524
537
|
left = true;
|
|
525
538
|
if (infoRect.width <= (left ? spaceLeft : spaceRight)) {
|
|
526
|
-
top = (Math.max(
|
|
539
|
+
top = (Math.max(space.top, Math.min(selRect.top, space.bottom - infoRect.height)) - listRect.top) + "px";
|
|
527
540
|
maxWidth = Math.min(400 /* Info.Width */, left ? spaceLeft : spaceRight) + "px";
|
|
528
541
|
}
|
|
529
542
|
else {
|
|
530
543
|
narrow = true;
|
|
531
|
-
maxWidth = Math.min(400 /* Info.Width */, (rtl ? listRect.right :
|
|
532
|
-
let spaceBelow =
|
|
544
|
+
maxWidth = Math.min(400 /* Info.Width */, (rtl ? listRect.right : space.right - listRect.left) - 30 /* Info.Margin */) + "px";
|
|
545
|
+
let spaceBelow = space.bottom - listRect.bottom;
|
|
533
546
|
if (spaceBelow >= infoRect.height || spaceBelow > listRect.top) // Below the completion
|
|
534
547
|
top = (selRect.bottom - listRect.top) + "px";
|
|
535
548
|
else // Above it
|
|
@@ -638,21 +651,24 @@ function sortOptions(active, state) {
|
|
|
638
651
|
return result;
|
|
639
652
|
}
|
|
640
653
|
class CompletionDialog {
|
|
641
|
-
constructor(options, attrs, tooltip, timestamp, selected) {
|
|
654
|
+
constructor(options, attrs, tooltip, timestamp, selected, disabled) {
|
|
642
655
|
this.options = options;
|
|
643
656
|
this.attrs = attrs;
|
|
644
657
|
this.tooltip = tooltip;
|
|
645
658
|
this.timestamp = timestamp;
|
|
646
659
|
this.selected = selected;
|
|
660
|
+
this.disabled = disabled;
|
|
647
661
|
}
|
|
648
662
|
setSelected(selected, id) {
|
|
649
663
|
return selected == this.selected || selected >= this.options.length ? this
|
|
650
|
-
: new CompletionDialog(this.options, makeAttrs(id, selected), this.tooltip, this.timestamp, selected);
|
|
664
|
+
: new CompletionDialog(this.options, makeAttrs(id, selected), this.tooltip, this.timestamp, selected, this.disabled);
|
|
651
665
|
}
|
|
652
666
|
static build(active, state, id, prev, conf) {
|
|
653
667
|
let options = sortOptions(active, state);
|
|
654
|
-
if (!options.length)
|
|
655
|
-
return
|
|
668
|
+
if (!options.length) {
|
|
669
|
+
return prev && active.some(a => a.state == 1 /* State.Pending */) ?
|
|
670
|
+
new CompletionDialog(prev.options, prev.attrs, prev.tooltip, prev.timestamp, prev.selected, true) : null;
|
|
671
|
+
}
|
|
656
672
|
let selected = state.facet(completionConfig).selectOnOpen ? 0 : -1;
|
|
657
673
|
if (prev && prev.selected != selected && prev.selected != -1) {
|
|
658
674
|
let selectedValue = prev.options[prev.selected].completion;
|
|
@@ -666,10 +682,10 @@ class CompletionDialog {
|
|
|
666
682
|
pos: active.reduce((a, b) => b.hasResult() ? Math.min(a, b.from) : a, 1e8),
|
|
667
683
|
create: completionTooltip(completionState),
|
|
668
684
|
above: conf.aboveCursor,
|
|
669
|
-
}, prev ? prev.timestamp : Date.now(), selected);
|
|
685
|
+
}, prev ? prev.timestamp : Date.now(), selected, false);
|
|
670
686
|
}
|
|
671
687
|
map(changes) {
|
|
672
|
-
return new CompletionDialog(this.options, this.attrs, Object.assign(Object.assign({}, this.tooltip), { pos: changes.mapPos(this.tooltip.pos) }), this.timestamp, this.selected);
|
|
688
|
+
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);
|
|
673
689
|
}
|
|
674
690
|
}
|
|
675
691
|
class CompletionState {
|
|
@@ -692,9 +708,12 @@ class CompletionState {
|
|
|
692
708
|
});
|
|
693
709
|
if (active.length == this.active.length && active.every((a, i) => a == this.active[i]))
|
|
694
710
|
active = this.active;
|
|
695
|
-
let open =
|
|
696
|
-
|
|
697
|
-
|
|
711
|
+
let open = this.open;
|
|
712
|
+
if (tr.selection || active.some(a => a.hasResult() && tr.changes.touchesRange(a.from, a.to)) ||
|
|
713
|
+
!sameResults(active, this.active))
|
|
714
|
+
open = CompletionDialog.build(active, state, this.id, this.open, conf);
|
|
715
|
+
else if (open && tr.docChanged)
|
|
716
|
+
open = open.map(tr.changes);
|
|
698
717
|
if (!open && active.every(a => a.state != 1 /* State.Pending */) && active.some(a => a.hasResult()))
|
|
699
718
|
active = active.map(a => a.hasResult() ? new ActiveSource(a.source, 0 /* State.Inactive */) : a);
|
|
700
719
|
for (let effect of tr.effects)
|
|
@@ -834,7 +853,7 @@ backward by the given amount.
|
|
|
834
853
|
function moveCompletionSelection(forward, by = "option") {
|
|
835
854
|
return (view$1) => {
|
|
836
855
|
let cState = view$1.state.field(completionState, false);
|
|
837
|
-
if (!cState || !cState.open ||
|
|
856
|
+
if (!cState || !cState.open || cState.open.disabled ||
|
|
838
857
|
Date.now() - cState.open.timestamp < view$1.state.facet(completionConfig).interactionDelay)
|
|
839
858
|
return false;
|
|
840
859
|
let step = 1, tooltip;
|
|
@@ -859,7 +878,8 @@ const acceptCompletion = (view) => {
|
|
|
859
878
|
if (view.state.readOnly || !cState || !cState.open || cState.open.selected < 0 ||
|
|
860
879
|
Date.now() - cState.open.timestamp < view.state.facet(completionConfig).interactionDelay)
|
|
861
880
|
return false;
|
|
862
|
-
|
|
881
|
+
if (!cState.open.disabled)
|
|
882
|
+
applyCompletion(view, cState.open.options[cState.open.selected]);
|
|
863
883
|
return true;
|
|
864
884
|
};
|
|
865
885
|
/**
|
|
@@ -1064,10 +1084,16 @@ const baseTheme = view.EditorView.baseTheme({
|
|
|
1064
1084
|
background: "#17c",
|
|
1065
1085
|
color: "white",
|
|
1066
1086
|
},
|
|
1087
|
+
"&light .cm-tooltip-autocomplete-disabled ul li[aria-selected]": {
|
|
1088
|
+
background: "#777",
|
|
1089
|
+
},
|
|
1067
1090
|
"&dark .cm-tooltip-autocomplete ul li[aria-selected]": {
|
|
1068
1091
|
background: "#347",
|
|
1069
1092
|
color: "white",
|
|
1070
1093
|
},
|
|
1094
|
+
"&dark .cm-tooltip-autocomplete-disabled ul li[aria-selected]": {
|
|
1095
|
+
background: "#444",
|
|
1096
|
+
},
|
|
1071
1097
|
".cm-completionListIncompleteTop:before, .cm-completionListIncompleteBottom:after": {
|
|
1072
1098
|
content: '"···"',
|
|
1073
1099
|
opacity: 0.5,
|
|
@@ -1776,7 +1802,7 @@ Returns the available completions as an array.
|
|
|
1776
1802
|
function currentCompletions(state) {
|
|
1777
1803
|
var _a;
|
|
1778
1804
|
let open = (_a = state.field(completionState, false)) === null || _a === void 0 ? void 0 : _a.open;
|
|
1779
|
-
if (!open)
|
|
1805
|
+
if (!open || open.disabled)
|
|
1780
1806
|
return [];
|
|
1781
1807
|
let completions = completionArrayCache.get(open.options);
|
|
1782
1808
|
if (!completions)
|
|
@@ -1789,7 +1815,7 @@ Return the currently selected completion, if any.
|
|
|
1789
1815
|
function selectedCompletion(state) {
|
|
1790
1816
|
var _a;
|
|
1791
1817
|
let open = (_a = state.field(completionState, false)) === null || _a === void 0 ? void 0 : _a.open;
|
|
1792
|
-
return open && open.selected >= 0 ? open.options[open.selected].completion : null;
|
|
1818
|
+
return open && !open.disabled && open.selected >= 0 ? open.options[open.selected].completion : null;
|
|
1793
1819
|
}
|
|
1794
1820
|
/**
|
|
1795
1821
|
Returns the currently selected position in the active completion
|
|
@@ -1798,7 +1824,7 @@ list, or null if no completions are active.
|
|
|
1798
1824
|
function selectedCompletionIndex(state) {
|
|
1799
1825
|
var _a;
|
|
1800
1826
|
let open = (_a = state.field(completionState, false)) === null || _a === void 0 ? void 0 : _a.open;
|
|
1801
|
-
return open && open.selected >= 0 ? open.selected : null;
|
|
1827
|
+
return open && !open.disabled && open.selected >= 0 ? open.selected : null;
|
|
1802
1828
|
}
|
|
1803
1829
|
/**
|
|
1804
1830
|
Create an effect that can be attached to a transaction to change
|
package/dist/index.js
CHANGED
|
@@ -175,7 +175,7 @@ function applyCompletion(view, option) {
|
|
|
175
175
|
const apply = option.completion.apply || option.completion.label;
|
|
176
176
|
let result = option.source;
|
|
177
177
|
if (typeof apply == "string")
|
|
178
|
-
view.dispatch(insertCompletionText(view.state, apply, result.from, result.to));
|
|
178
|
+
view.dispatch(Object.assign(Object.assign({}, insertCompletionText(view.state, apply, result.from, result.to)), { annotations: pickedCompletion.of(option.completion) }));
|
|
179
179
|
else
|
|
180
180
|
apply(view, option.completion, result.from, result.to);
|
|
181
181
|
}
|
|
@@ -410,6 +410,7 @@ class CompletionTooltip {
|
|
|
410
410
|
write: (pos) => this.positionInfo(pos),
|
|
411
411
|
key: this
|
|
412
412
|
};
|
|
413
|
+
this.space = null;
|
|
413
414
|
let cState = view.state.field(stateField);
|
|
414
415
|
let { options, selected } = cState.open;
|
|
415
416
|
let config = view.state.facet(completionConfig);
|
|
@@ -435,10 +436,17 @@ class CompletionTooltip {
|
|
|
435
436
|
}
|
|
436
437
|
mount() { this.updateSel(); }
|
|
437
438
|
update(update) {
|
|
438
|
-
|
|
439
|
+
var _a, _b, _c;
|
|
440
|
+
let cState = update.state.field(this.stateField);
|
|
441
|
+
let prevState = update.startState.field(this.stateField);
|
|
442
|
+
if (cState != prevState) {
|
|
439
443
|
this.updateSel();
|
|
444
|
+
if (((_a = cState.open) === null || _a === void 0 ? void 0 : _a.disabled) != ((_b = prevState.open) === null || _b === void 0 ? void 0 : _b.disabled))
|
|
445
|
+
this.dom.classList.toggle("cm-tooltip-autocomplete-disabled", !!((_c = cState.open) === null || _c === void 0 ? void 0 : _c.disabled));
|
|
446
|
+
}
|
|
440
447
|
}
|
|
441
|
-
positioned() {
|
|
448
|
+
positioned(space) {
|
|
449
|
+
this.space = space;
|
|
442
450
|
if (this.info)
|
|
443
451
|
this.view.requestMeasure(this.placeInfo);
|
|
444
452
|
}
|
|
@@ -505,27 +513,32 @@ class CompletionTooltip {
|
|
|
505
513
|
let sel = this.dom.querySelector("[aria-selected]");
|
|
506
514
|
if (!sel || !this.info)
|
|
507
515
|
return null;
|
|
508
|
-
let win = this.dom.ownerDocument.defaultView || window;
|
|
509
516
|
let listRect = this.dom.getBoundingClientRect();
|
|
510
517
|
let infoRect = this.info.getBoundingClientRect();
|
|
511
518
|
let selRect = sel.getBoundingClientRect();
|
|
512
|
-
|
|
519
|
+
let space = this.space;
|
|
520
|
+
if (!space) {
|
|
521
|
+
let win = this.dom.ownerDocument.defaultView || window;
|
|
522
|
+
space = { left: 0, top: 0, right: win.innerWidth, bottom: win.innerHeight };
|
|
523
|
+
}
|
|
524
|
+
if (selRect.top > Math.min(space.bottom, listRect.bottom) - 10 ||
|
|
525
|
+
selRect.bottom < Math.max(space.top, listRect.top) + 10)
|
|
513
526
|
return null;
|
|
514
527
|
let rtl = this.view.textDirection == Direction.RTL, left = rtl, narrow = false, maxWidth;
|
|
515
528
|
let top = "", bottom = "";
|
|
516
|
-
let spaceLeft = listRect.left, spaceRight =
|
|
529
|
+
let spaceLeft = listRect.left - space.left, spaceRight = space.right - listRect.right;
|
|
517
530
|
if (left && spaceLeft < Math.min(infoRect.width, spaceRight))
|
|
518
531
|
left = false;
|
|
519
532
|
else if (!left && spaceRight < Math.min(infoRect.width, spaceLeft))
|
|
520
533
|
left = true;
|
|
521
534
|
if (infoRect.width <= (left ? spaceLeft : spaceRight)) {
|
|
522
|
-
top = (Math.max(
|
|
535
|
+
top = (Math.max(space.top, Math.min(selRect.top, space.bottom - infoRect.height)) - listRect.top) + "px";
|
|
523
536
|
maxWidth = Math.min(400 /* Info.Width */, left ? spaceLeft : spaceRight) + "px";
|
|
524
537
|
}
|
|
525
538
|
else {
|
|
526
539
|
narrow = true;
|
|
527
|
-
maxWidth = Math.min(400 /* Info.Width */, (rtl ? listRect.right :
|
|
528
|
-
let spaceBelow =
|
|
540
|
+
maxWidth = Math.min(400 /* Info.Width */, (rtl ? listRect.right : space.right - listRect.left) - 30 /* Info.Margin */) + "px";
|
|
541
|
+
let spaceBelow = space.bottom - listRect.bottom;
|
|
529
542
|
if (spaceBelow >= infoRect.height || spaceBelow > listRect.top) // Below the completion
|
|
530
543
|
top = (selRect.bottom - listRect.top) + "px";
|
|
531
544
|
else // Above it
|
|
@@ -634,21 +647,24 @@ function sortOptions(active, state) {
|
|
|
634
647
|
return result;
|
|
635
648
|
}
|
|
636
649
|
class CompletionDialog {
|
|
637
|
-
constructor(options, attrs, tooltip, timestamp, selected) {
|
|
650
|
+
constructor(options, attrs, tooltip, timestamp, selected, disabled) {
|
|
638
651
|
this.options = options;
|
|
639
652
|
this.attrs = attrs;
|
|
640
653
|
this.tooltip = tooltip;
|
|
641
654
|
this.timestamp = timestamp;
|
|
642
655
|
this.selected = selected;
|
|
656
|
+
this.disabled = disabled;
|
|
643
657
|
}
|
|
644
658
|
setSelected(selected, id) {
|
|
645
659
|
return selected == this.selected || selected >= this.options.length ? this
|
|
646
|
-
: new CompletionDialog(this.options, makeAttrs(id, selected), this.tooltip, this.timestamp, selected);
|
|
660
|
+
: new CompletionDialog(this.options, makeAttrs(id, selected), this.tooltip, this.timestamp, selected, this.disabled);
|
|
647
661
|
}
|
|
648
662
|
static build(active, state, id, prev, conf) {
|
|
649
663
|
let options = sortOptions(active, state);
|
|
650
|
-
if (!options.length)
|
|
651
|
-
return
|
|
664
|
+
if (!options.length) {
|
|
665
|
+
return prev && active.some(a => a.state == 1 /* State.Pending */) ?
|
|
666
|
+
new CompletionDialog(prev.options, prev.attrs, prev.tooltip, prev.timestamp, prev.selected, true) : null;
|
|
667
|
+
}
|
|
652
668
|
let selected = state.facet(completionConfig).selectOnOpen ? 0 : -1;
|
|
653
669
|
if (prev && prev.selected != selected && prev.selected != -1) {
|
|
654
670
|
let selectedValue = prev.options[prev.selected].completion;
|
|
@@ -662,10 +678,10 @@ class CompletionDialog {
|
|
|
662
678
|
pos: active.reduce((a, b) => b.hasResult() ? Math.min(a, b.from) : a, 1e8),
|
|
663
679
|
create: completionTooltip(completionState),
|
|
664
680
|
above: conf.aboveCursor,
|
|
665
|
-
}, prev ? prev.timestamp : Date.now(), selected);
|
|
681
|
+
}, prev ? prev.timestamp : Date.now(), selected, false);
|
|
666
682
|
}
|
|
667
683
|
map(changes) {
|
|
668
|
-
return new CompletionDialog(this.options, this.attrs, Object.assign(Object.assign({}, this.tooltip), { pos: changes.mapPos(this.tooltip.pos) }), this.timestamp, this.selected);
|
|
684
|
+
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);
|
|
669
685
|
}
|
|
670
686
|
}
|
|
671
687
|
class CompletionState {
|
|
@@ -688,9 +704,12 @@ class CompletionState {
|
|
|
688
704
|
});
|
|
689
705
|
if (active.length == this.active.length && active.every((a, i) => a == this.active[i]))
|
|
690
706
|
active = this.active;
|
|
691
|
-
let open =
|
|
692
|
-
|
|
693
|
-
|
|
707
|
+
let open = this.open;
|
|
708
|
+
if (tr.selection || active.some(a => a.hasResult() && tr.changes.touchesRange(a.from, a.to)) ||
|
|
709
|
+
!sameResults(active, this.active))
|
|
710
|
+
open = CompletionDialog.build(active, state, this.id, this.open, conf);
|
|
711
|
+
else if (open && tr.docChanged)
|
|
712
|
+
open = open.map(tr.changes);
|
|
694
713
|
if (!open && active.every(a => a.state != 1 /* State.Pending */) && active.some(a => a.hasResult()))
|
|
695
714
|
active = active.map(a => a.hasResult() ? new ActiveSource(a.source, 0 /* State.Inactive */) : a);
|
|
696
715
|
for (let effect of tr.effects)
|
|
@@ -830,7 +849,7 @@ backward by the given amount.
|
|
|
830
849
|
function moveCompletionSelection(forward, by = "option") {
|
|
831
850
|
return (view) => {
|
|
832
851
|
let cState = view.state.field(completionState, false);
|
|
833
|
-
if (!cState || !cState.open ||
|
|
852
|
+
if (!cState || !cState.open || cState.open.disabled ||
|
|
834
853
|
Date.now() - cState.open.timestamp < view.state.facet(completionConfig).interactionDelay)
|
|
835
854
|
return false;
|
|
836
855
|
let step = 1, tooltip;
|
|
@@ -855,7 +874,8 @@ const acceptCompletion = (view) => {
|
|
|
855
874
|
if (view.state.readOnly || !cState || !cState.open || cState.open.selected < 0 ||
|
|
856
875
|
Date.now() - cState.open.timestamp < view.state.facet(completionConfig).interactionDelay)
|
|
857
876
|
return false;
|
|
858
|
-
|
|
877
|
+
if (!cState.open.disabled)
|
|
878
|
+
applyCompletion(view, cState.open.options[cState.open.selected]);
|
|
859
879
|
return true;
|
|
860
880
|
};
|
|
861
881
|
/**
|
|
@@ -1060,10 +1080,16 @@ const baseTheme = /*@__PURE__*/EditorView.baseTheme({
|
|
|
1060
1080
|
background: "#17c",
|
|
1061
1081
|
color: "white",
|
|
1062
1082
|
},
|
|
1083
|
+
"&light .cm-tooltip-autocomplete-disabled ul li[aria-selected]": {
|
|
1084
|
+
background: "#777",
|
|
1085
|
+
},
|
|
1063
1086
|
"&dark .cm-tooltip-autocomplete ul li[aria-selected]": {
|
|
1064
1087
|
background: "#347",
|
|
1065
1088
|
color: "white",
|
|
1066
1089
|
},
|
|
1090
|
+
"&dark .cm-tooltip-autocomplete-disabled ul li[aria-selected]": {
|
|
1091
|
+
background: "#444",
|
|
1092
|
+
},
|
|
1067
1093
|
".cm-completionListIncompleteTop:before, .cm-completionListIncompleteBottom:after": {
|
|
1068
1094
|
content: '"···"',
|
|
1069
1095
|
opacity: 0.5,
|
|
@@ -1772,7 +1798,7 @@ Returns the available completions as an array.
|
|
|
1772
1798
|
function currentCompletions(state) {
|
|
1773
1799
|
var _a;
|
|
1774
1800
|
let open = (_a = state.field(completionState, false)) === null || _a === void 0 ? void 0 : _a.open;
|
|
1775
|
-
if (!open)
|
|
1801
|
+
if (!open || open.disabled)
|
|
1776
1802
|
return [];
|
|
1777
1803
|
let completions = completionArrayCache.get(open.options);
|
|
1778
1804
|
if (!completions)
|
|
@@ -1785,7 +1811,7 @@ Return the currently selected completion, if any.
|
|
|
1785
1811
|
function selectedCompletion(state) {
|
|
1786
1812
|
var _a;
|
|
1787
1813
|
let open = (_a = state.field(completionState, false)) === null || _a === void 0 ? void 0 : _a.open;
|
|
1788
|
-
return open && open.selected >= 0 ? open.options[open.selected].completion : null;
|
|
1814
|
+
return open && !open.disabled && open.selected >= 0 ? open.options[open.selected].completion : null;
|
|
1789
1815
|
}
|
|
1790
1816
|
/**
|
|
1791
1817
|
Returns the currently selected position in the active completion
|
|
@@ -1794,7 +1820,7 @@ list, or null if no completions are active.
|
|
|
1794
1820
|
function selectedCompletionIndex(state) {
|
|
1795
1821
|
var _a;
|
|
1796
1822
|
let open = (_a = state.field(completionState, false)) === null || _a === void 0 ? void 0 : _a.open;
|
|
1797
|
-
return open && open.selected >= 0 ? open.selected : null;
|
|
1823
|
+
return open && !open.disabled && open.selected >= 0 ? open.selected : null;
|
|
1798
1824
|
}
|
|
1799
1825
|
/**
|
|
1800
1826
|
Create an effect that can be attached to a transaction to change
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codemirror/autocomplete",
|
|
3
|
-
"version": "6.3.
|
|
3
|
+
"version": "6.3.1",
|
|
4
4
|
"description": "Autocompletion for the CodeMirror code editor",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "cm-runtests",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@codemirror/language": "^6.0.0",
|
|
30
30
|
"@codemirror/state": "^6.0.0",
|
|
31
|
-
"@codemirror/view": "^6.
|
|
31
|
+
"@codemirror/view": "^6.5.0",
|
|
32
32
|
"@lezer/common": "^1.0.0"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|