Autocomplete 'match mode' setting

for #114
This commit is contained in:
Alex "mcmonkey" Goodwin
2024-09-14 20:49:20 +09:00
parent aa98e4d06e
commit f54dbb5c9c
2 changed files with 22 additions and 3 deletions

View File

@@ -396,6 +396,11 @@ public class Settings : AutoConfiguration
[ConfigComment("Optional suffix to append to autocompletes, eg ', ' to append commas.")]
public string Suffix = "";
[ConfigComment("How to match and list results.\n'Contains' lists any match that contains your current text\n'StartsWith' only lists matches that start with your current text\n'Bucketed' shows StartsWith matches first, and Contains matches after.")]
[ManualSettingsOptions(Impl = null, Vals = ["Bucketed", "Contains", "StartsWith"])]
public string MatchMode = "Bucketed";
}
}

View File

@@ -1275,6 +1275,7 @@ class PromptTabCompleteClass {
}
let wordLow = word.toLowerCase();
let rawMatchSet = [];
let matchMode = getUserSetting('autocomplete.matchmode');
if (completionSet) {
let startWithList = [];
let containList = [];
@@ -1290,9 +1291,22 @@ class PromptTabCompleteClass {
rawMatchSet.push(entry);
}
}
startWithList.sort((a, b) => a.low.length - b.low.length || a.low.localeCompare(b.low));
containList.sort((a, b) => a.low.length - b.low.length || a.low.localeCompare(b.low));
baseList = startWithList.concat(containList);
let doSortList = (list) => {
return list.sort((a, b) => a.low.length - b.low.length || a.low.localeCompare(b.low));
}
if (matchMode == 'Bucketed') {
doSortList(startWithList);
doSortList(containList);
baseList = startWithList.concat(containList);
}
else if (matchMode == 'Contains') {
doSortList(rawMatchSet);
baseList = rawMatchSet;
}
else if (matchMode == 'StartsWith') {
doSortList(startWithList);
baseList = startWithList;
}
if (baseList.length > 50) {
baseList = baseList.slice(0, 50);
}