Replace complex autosuggestions filtering function with simple one

This commit is contained in:
Sherfin Shamsudeen 2025-01-13 18:33:29 +05:30
parent be3f73c099
commit f9a4a9962c

View file

@ -156,35 +156,11 @@ export const generateHints = (hints, totalReferences = 1, input, searchText) =>
function filterHintsByDepth(input, hints) {
if (input === '') return hints;
const inputDepth = input.includes('.') ? input.split('.').length : 0;
const inputParts = input.split('.');
const filteredHints = hints.filter((cm) => {
const hintParts = cm.hint.split('.');
let shouldInclude =
(cm.hint.startsWith(input) && hintParts.length === inputDepth + 1) ||
(cm.hint.startsWith(input) && hintParts.length === inputDepth);
const shouldFuzzyMatch = !shouldInclude ? hintParts.length > inputDepth : false;
if (shouldFuzzyMatch) {
// fuzzy match
let matchedDepth = -1;
for (let i = 0; i < hintParts.length; i++) {
if (hintParts[i].includes(input)) {
matchedDepth = i;
break;
}
}
if (matchedDepth !== -1) {
shouldInclude = hintParts.length === matchedDepth + 1;
}
} else if (input.endsWith('.')) {
shouldInclude = cm.hint.startsWith(input) && hintParts.length === inputDepth;
}
return shouldInclude;
const filteredHints = hints.filter((hint) => {
const hintParts = hint.hint.split('.');
return hintParts.length <= inputParts.length + 1;
});
return filteredHints;