@codemirror/autocomplete 6.3.0 → 6.3.2
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 +16 -0
- package/dist/index.cjs +51 -23
- package/dist/index.js +51 -23
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
## 6.3.2 (2022-11-15)
|
|
2
|
+
|
|
3
|
+
### Bug fixes
|
|
4
|
+
|
|
5
|
+
Fix a regression that could cause the completion dialog to stick around when it should be hidden.
|
|
6
|
+
|
|
7
|
+
## 6.3.1 (2022-11-14)
|
|
8
|
+
|
|
9
|
+
### Bug fixes
|
|
10
|
+
|
|
11
|
+
Fix a regression where transactions for picking a completion (without custom `apply` method) no longer had the `pickedCompletion` annotation.
|
|
12
|
+
|
|
13
|
+
Reduce flickering for completion sources without `validFor` info by temporarily showing a disabled tooltip while the completion updates.
|
|
14
|
+
|
|
15
|
+
Make sure completion info tooltips are kept within the space provided by the `tooltipSpace` option.
|
|
16
|
+
|
|
1
17
|
## 6.3.0 (2022-09-22)
|
|
2
18
|
|
|
3
19
|
### 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,14 @@ 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 && open.disabled && !active.some(a => a.state == 1 /* State.Pending */))
|
|
716
|
+
open = null;
|
|
717
|
+
else if (open && tr.docChanged)
|
|
718
|
+
open = open.map(tr.changes);
|
|
698
719
|
if (!open && active.every(a => a.state != 1 /* State.Pending */) && active.some(a => a.hasResult()))
|
|
699
720
|
active = active.map(a => a.hasResult() ? new ActiveSource(a.source, 0 /* State.Inactive */) : a);
|
|
700
721
|
for (let effect of tr.effects)
|
|
@@ -834,7 +855,7 @@ backward by the given amount.
|
|
|
834
855
|
function moveCompletionSelection(forward, by = "option") {
|
|
835
856
|
return (view$1) => {
|
|
836
857
|
let cState = view$1.state.field(completionState, false);
|
|
837
|
-
if (!cState || !cState.open ||
|
|
858
|
+
if (!cState || !cState.open || cState.open.disabled ||
|
|
838
859
|
Date.now() - cState.open.timestamp < view$1.state.facet(completionConfig).interactionDelay)
|
|
839
860
|
return false;
|
|
840
861
|
let step = 1, tooltip;
|
|
@@ -859,7 +880,8 @@ const acceptCompletion = (view) => {
|
|
|
859
880
|
if (view.state.readOnly || !cState || !cState.open || cState.open.selected < 0 ||
|
|
860
881
|
Date.now() - cState.open.timestamp < view.state.facet(completionConfig).interactionDelay)
|
|
861
882
|
return false;
|
|
862
|
-
|
|
883
|
+
if (!cState.open.disabled)
|
|
884
|
+
applyCompletion(view, cState.open.options[cState.open.selected]);
|
|
863
885
|
return true;
|
|
864
886
|
};
|
|
865
887
|
/**
|
|
@@ -1064,10 +1086,16 @@ const baseTheme = view.EditorView.baseTheme({
|
|
|
1064
1086
|
background: "#17c",
|
|
1065
1087
|
color: "white",
|
|
1066
1088
|
},
|
|
1089
|
+
"&light .cm-tooltip-autocomplete-disabled ul li[aria-selected]": {
|
|
1090
|
+
background: "#777",
|
|
1091
|
+
},
|
|
1067
1092
|
"&dark .cm-tooltip-autocomplete ul li[aria-selected]": {
|
|
1068
1093
|
background: "#347",
|
|
1069
1094
|
color: "white",
|
|
1070
1095
|
},
|
|
1096
|
+
"&dark .cm-tooltip-autocomplete-disabled ul li[aria-selected]": {
|
|
1097
|
+
background: "#444",
|
|
1098
|
+
},
|
|
1071
1099
|
".cm-completionListIncompleteTop:before, .cm-completionListIncompleteBottom:after": {
|
|
1072
1100
|
content: '"···"',
|
|
1073
1101
|
opacity: 0.5,
|
|
@@ -1776,7 +1804,7 @@ Returns the available completions as an array.
|
|
|
1776
1804
|
function currentCompletions(state) {
|
|
1777
1805
|
var _a;
|
|
1778
1806
|
let open = (_a = state.field(completionState, false)) === null || _a === void 0 ? void 0 : _a.open;
|
|
1779
|
-
if (!open)
|
|
1807
|
+
if (!open || open.disabled)
|
|
1780
1808
|
return [];
|
|
1781
1809
|
let completions = completionArrayCache.get(open.options);
|
|
1782
1810
|
if (!completions)
|
|
@@ -1789,7 +1817,7 @@ Return the currently selected completion, if any.
|
|
|
1789
1817
|
function selectedCompletion(state) {
|
|
1790
1818
|
var _a;
|
|
1791
1819
|
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;
|
|
1820
|
+
return open && !open.disabled && open.selected >= 0 ? open.options[open.selected].completion : null;
|
|
1793
1821
|
}
|
|
1794
1822
|
/**
|
|
1795
1823
|
Returns the currently selected position in the active completion
|
|
@@ -1798,7 +1826,7 @@ list, or null if no completions are active.
|
|
|
1798
1826
|
function selectedCompletionIndex(state) {
|
|
1799
1827
|
var _a;
|
|
1800
1828
|
let open = (_a = state.field(completionState, false)) === null || _a === void 0 ? void 0 : _a.open;
|
|
1801
|
-
return open && open.selected >= 0 ? open.selected : null;
|
|
1829
|
+
return open && !open.disabled && open.selected >= 0 ? open.selected : null;
|
|
1802
1830
|
}
|
|
1803
1831
|
/**
|
|
1804
1832
|
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,14 @@ 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 && open.disabled && !active.some(a => a.state == 1 /* State.Pending */))
|
|
712
|
+
open = null;
|
|
713
|
+
else if (open && tr.docChanged)
|
|
714
|
+
open = open.map(tr.changes);
|
|
694
715
|
if (!open && active.every(a => a.state != 1 /* State.Pending */) && active.some(a => a.hasResult()))
|
|
695
716
|
active = active.map(a => a.hasResult() ? new ActiveSource(a.source, 0 /* State.Inactive */) : a);
|
|
696
717
|
for (let effect of tr.effects)
|
|
@@ -830,7 +851,7 @@ backward by the given amount.
|
|
|
830
851
|
function moveCompletionSelection(forward, by = "option") {
|
|
831
852
|
return (view) => {
|
|
832
853
|
let cState = view.state.field(completionState, false);
|
|
833
|
-
if (!cState || !cState.open ||
|
|
854
|
+
if (!cState || !cState.open || cState.open.disabled ||
|
|
834
855
|
Date.now() - cState.open.timestamp < view.state.facet(completionConfig).interactionDelay)
|
|
835
856
|
return false;
|
|
836
857
|
let step = 1, tooltip;
|
|
@@ -855,7 +876,8 @@ const acceptCompletion = (view) => {
|
|
|
855
876
|
if (view.state.readOnly || !cState || !cState.open || cState.open.selected < 0 ||
|
|
856
877
|
Date.now() - cState.open.timestamp < view.state.facet(completionConfig).interactionDelay)
|
|
857
878
|
return false;
|
|
858
|
-
|
|
879
|
+
if (!cState.open.disabled)
|
|
880
|
+
applyCompletion(view, cState.open.options[cState.open.selected]);
|
|
859
881
|
return true;
|
|
860
882
|
};
|
|
861
883
|
/**
|
|
@@ -1060,10 +1082,16 @@ const baseTheme = /*@__PURE__*/EditorView.baseTheme({
|
|
|
1060
1082
|
background: "#17c",
|
|
1061
1083
|
color: "white",
|
|
1062
1084
|
},
|
|
1085
|
+
"&light .cm-tooltip-autocomplete-disabled ul li[aria-selected]": {
|
|
1086
|
+
background: "#777",
|
|
1087
|
+
},
|
|
1063
1088
|
"&dark .cm-tooltip-autocomplete ul li[aria-selected]": {
|
|
1064
1089
|
background: "#347",
|
|
1065
1090
|
color: "white",
|
|
1066
1091
|
},
|
|
1092
|
+
"&dark .cm-tooltip-autocomplete-disabled ul li[aria-selected]": {
|
|
1093
|
+
background: "#444",
|
|
1094
|
+
},
|
|
1067
1095
|
".cm-completionListIncompleteTop:before, .cm-completionListIncompleteBottom:after": {
|
|
1068
1096
|
content: '"···"',
|
|
1069
1097
|
opacity: 0.5,
|
|
@@ -1772,7 +1800,7 @@ Returns the available completions as an array.
|
|
|
1772
1800
|
function currentCompletions(state) {
|
|
1773
1801
|
var _a;
|
|
1774
1802
|
let open = (_a = state.field(completionState, false)) === null || _a === void 0 ? void 0 : _a.open;
|
|
1775
|
-
if (!open)
|
|
1803
|
+
if (!open || open.disabled)
|
|
1776
1804
|
return [];
|
|
1777
1805
|
let completions = completionArrayCache.get(open.options);
|
|
1778
1806
|
if (!completions)
|
|
@@ -1785,7 +1813,7 @@ Return the currently selected completion, if any.
|
|
|
1785
1813
|
function selectedCompletion(state) {
|
|
1786
1814
|
var _a;
|
|
1787
1815
|
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;
|
|
1816
|
+
return open && !open.disabled && open.selected >= 0 ? open.options[open.selected].completion : null;
|
|
1789
1817
|
}
|
|
1790
1818
|
/**
|
|
1791
1819
|
Returns the currently selected position in the active completion
|
|
@@ -1794,7 +1822,7 @@ list, or null if no completions are active.
|
|
|
1794
1822
|
function selectedCompletionIndex(state) {
|
|
1795
1823
|
var _a;
|
|
1796
1824
|
let open = (_a = state.field(completionState, false)) === null || _a === void 0 ? void 0 : _a.open;
|
|
1797
|
-
return open && open.selected >= 0 ? open.selected : null;
|
|
1825
|
+
return open && !open.disabled && open.selected >= 0 ? open.selected : null;
|
|
1798
1826
|
}
|
|
1799
1827
|
/**
|
|
1800
1828
|
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.2",
|
|
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": {
|