mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-23 08:58:26 +00:00
Replace complex autosuggestions filtering function with simple one
This commit is contained in:
parent
be3f73c099
commit
f9a4a9962c
1 changed files with 4 additions and 28 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue