@codemirror/autocomplete 6.18.7 → 6.19.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 +6 -0
- package/dist/index.cjs +14 -3
- package/dist/index.d.cts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +14 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -754,7 +754,7 @@ function score(option) {
|
|
|
754
754
|
}
|
|
755
755
|
function sortOptions(active, state) {
|
|
756
756
|
let options = [];
|
|
757
|
-
let sections = null;
|
|
757
|
+
let sections = null, dynamicSectionScore = null;
|
|
758
758
|
let addOption = (option) => {
|
|
759
759
|
options.push(option);
|
|
760
760
|
let { section } = option.completion;
|
|
@@ -781,13 +781,24 @@ function sortOptions(active, state) {
|
|
|
781
781
|
for (let option of a.result.options)
|
|
782
782
|
if (match = matcher.match(option.label)) {
|
|
783
783
|
let matched = !option.displayLabel ? match.matched : getMatch ? getMatch(option, match.matched) : [];
|
|
784
|
-
|
|
784
|
+
let score = match.score + (option.boost || 0);
|
|
785
|
+
addOption(new Option(option, a.source, matched, score));
|
|
786
|
+
if (typeof option.section == "object" && option.section.rank === "dynamic") {
|
|
787
|
+
let { name } = option.section;
|
|
788
|
+
if (!dynamicSectionScore)
|
|
789
|
+
dynamicSectionScore = Object.create(null);
|
|
790
|
+
dynamicSectionScore[name] = Math.max(score, dynamicSectionScore[name] || -1e9);
|
|
791
|
+
}
|
|
785
792
|
}
|
|
786
793
|
}
|
|
787
794
|
}
|
|
788
795
|
if (sections) {
|
|
789
796
|
let sectionOrder = Object.create(null), pos = 0;
|
|
790
|
-
let cmp = (a, b) => {
|
|
797
|
+
let cmp = (a, b) => {
|
|
798
|
+
return (a.rank === "dynamic" && b.rank === "dynamic" ? dynamicSectionScore[b.name] - dynamicSectionScore[a.name] : 0) ||
|
|
799
|
+
(typeof a.rank == "number" ? a.rank : 1e9) - (typeof b.rank == "number" ? b.rank : 1e9) ||
|
|
800
|
+
(a.name < b.name ? -1 : 1);
|
|
801
|
+
};
|
|
791
802
|
for (let s of sections.sort(cmp)) {
|
|
792
803
|
pos -= 1e5;
|
|
793
804
|
sectionOrder[s.name] = pos;
|
package/dist/index.d.cts
CHANGED
|
@@ -106,8 +106,12 @@ interface CompletionSection {
|
|
|
106
106
|
By default, sections are ordered alphabetically by name. To
|
|
107
107
|
specify an explicit order, `rank` can be used. Sections with a
|
|
108
108
|
lower rank will be shown above sections with a higher rank.
|
|
109
|
+
|
|
110
|
+
When set to `"dynamic"`, the section's position compared to
|
|
111
|
+
other dynamic sections depends on the matching score of the
|
|
112
|
+
best-matching option in the sections.
|
|
109
113
|
*/
|
|
110
|
-
rank?: number;
|
|
114
|
+
rank?: number | "dynamic";
|
|
111
115
|
}
|
|
112
116
|
/**
|
|
113
117
|
An instance of this is passed to completion source functions.
|
package/dist/index.d.ts
CHANGED
|
@@ -106,8 +106,12 @@ interface CompletionSection {
|
|
|
106
106
|
By default, sections are ordered alphabetically by name. To
|
|
107
107
|
specify an explicit order, `rank` can be used. Sections with a
|
|
108
108
|
lower rank will be shown above sections with a higher rank.
|
|
109
|
+
|
|
110
|
+
When set to `"dynamic"`, the section's position compared to
|
|
111
|
+
other dynamic sections depends on the matching score of the
|
|
112
|
+
best-matching option in the sections.
|
|
109
113
|
*/
|
|
110
|
-
rank?: number;
|
|
114
|
+
rank?: number | "dynamic";
|
|
111
115
|
}
|
|
112
116
|
/**
|
|
113
117
|
An instance of this is passed to completion source functions.
|
package/dist/index.js
CHANGED
|
@@ -752,7 +752,7 @@ function score(option) {
|
|
|
752
752
|
}
|
|
753
753
|
function sortOptions(active, state) {
|
|
754
754
|
let options = [];
|
|
755
|
-
let sections = null;
|
|
755
|
+
let sections = null, dynamicSectionScore = null;
|
|
756
756
|
let addOption = (option) => {
|
|
757
757
|
options.push(option);
|
|
758
758
|
let { section } = option.completion;
|
|
@@ -779,13 +779,24 @@ function sortOptions(active, state) {
|
|
|
779
779
|
for (let option of a.result.options)
|
|
780
780
|
if (match = matcher.match(option.label)) {
|
|
781
781
|
let matched = !option.displayLabel ? match.matched : getMatch ? getMatch(option, match.matched) : [];
|
|
782
|
-
|
|
782
|
+
let score = match.score + (option.boost || 0);
|
|
783
|
+
addOption(new Option(option, a.source, matched, score));
|
|
784
|
+
if (typeof option.section == "object" && option.section.rank === "dynamic") {
|
|
785
|
+
let { name } = option.section;
|
|
786
|
+
if (!dynamicSectionScore)
|
|
787
|
+
dynamicSectionScore = Object.create(null);
|
|
788
|
+
dynamicSectionScore[name] = Math.max(score, dynamicSectionScore[name] || -1e9);
|
|
789
|
+
}
|
|
783
790
|
}
|
|
784
791
|
}
|
|
785
792
|
}
|
|
786
793
|
if (sections) {
|
|
787
794
|
let sectionOrder = Object.create(null), pos = 0;
|
|
788
|
-
let cmp = (a, b) => {
|
|
795
|
+
let cmp = (a, b) => {
|
|
796
|
+
return (a.rank === "dynamic" && b.rank === "dynamic" ? dynamicSectionScore[b.name] - dynamicSectionScore[a.name] : 0) ||
|
|
797
|
+
(typeof a.rank == "number" ? a.rank : 1e9) - (typeof b.rank == "number" ? b.rank : 1e9) ||
|
|
798
|
+
(a.name < b.name ? -1 : 1);
|
|
799
|
+
};
|
|
789
800
|
for (let s of sections.sort(cmp)) {
|
|
790
801
|
pos -= 1e5;
|
|
791
802
|
sectionOrder[s.name] = pos;
|