Removed unnecessary variable for line offset

This commit is contained in:
KoloMl 2025-02-11 12:24:24 +04:00
parent 63a9f0317f
commit 9a9f2de402

View file

@ -116,20 +116,18 @@ function findSelectedTerm(targetInput: InputFieldElement, searchQuery: string):
// actively edited line and use it instead of the whole value. // actively edited line and use it instead of the whole value.
const activeLineStart = searchQuery.slice(0, selectionIndex).lastIndexOf('\n') + 1; const activeLineStart = searchQuery.slice(0, selectionIndex).lastIndexOf('\n') + 1;
const lengthAfterSelectionIndex = Math.max(searchQuery.slice(selectionIndex).indexOf('\n'), 0); const lengthAfterSelectionIndex = Math.max(searchQuery.slice(selectionIndex).indexOf('\n'), 0);
const targetQuery = searchQuery.slice(activeLineStart, selectionIndex + lengthAfterSelectionIndex); const targetQuery = searchQuery.slice(activeLineStart, selectionIndex + lengthAfterSelectionIndex);
const lineOffset = activeLineStart;
const terms = getTermContexts(targetQuery); const terms = getTermContexts(targetQuery);
const searchIndex = selectionIndex - lineOffset; const searchIndex = selectionIndex - activeLineStart;
const term = terms.find(([range]) => range[0] < searchIndex && range[1] >= searchIndex) ?? null; const term = terms.find(([range]) => range[0] < searchIndex && range[1] >= searchIndex) ?? null;
// Converting line-specific indexes back to absolute ones. // Converting line-specific indexes back to absolute ones.
if (term) { if (term) {
const [range] = term; const [range] = term;
range[0] += lineOffset; range[0] += activeLineStart;
range[1] += lineOffset; range[1] += activeLineStart;
} }
return term; return term;