mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-02-13 09:24:22 +01:00
Removed unnecessary variable for line offset
This commit is contained in:
parent
63a9f0317f
commit
9a9f2de402
1 changed files with 3 additions and 5 deletions
|
@ -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;
|
||||||
|
|
Loading…
Reference in a new issue