mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-02-13 01:24:21 +01:00
Run active line search unconditionally
This commit is contained in:
parent
0b04fba4b4
commit
63a9f0317f
1 changed files with 5 additions and 11 deletions
|
@ -111,27 +111,21 @@ function findSelectedTerm(targetInput: InputFieldElement, searchQuery: string):
|
|||
if (targetInput.selectionStart === null || targetInput.selectionEnd === null) return null;
|
||||
|
||||
const selectionIndex = Math.min(targetInput.selectionStart, targetInput.selectionEnd);
|
||||
const isMultiline = targetInput instanceof HTMLTextAreaElement;
|
||||
|
||||
let lineOffset = 0;
|
||||
let targetQuery = searchQuery;
|
||||
|
||||
// Multi-line textarea elements should treat each line as the different search queries. Here we're looking for the
|
||||
// actively edited line and use it instead of the whole value.
|
||||
if (isMultiline) {
|
||||
const activeLineStart = searchQuery.slice(0, selectionIndex).lastIndexOf('\n') + 1;
|
||||
const lengthAfterSelectionIndex = Math.max(searchQuery.slice(selectionIndex).indexOf('\n'), 0);
|
||||
const activeLineStart = searchQuery.slice(0, selectionIndex).lastIndexOf('\n') + 1;
|
||||
const lengthAfterSelectionIndex = Math.max(searchQuery.slice(selectionIndex).indexOf('\n'), 0);
|
||||
|
||||
targetQuery = searchQuery.slice(activeLineStart, selectionIndex + lengthAfterSelectionIndex);
|
||||
lineOffset = activeLineStart;
|
||||
}
|
||||
const targetQuery = searchQuery.slice(activeLineStart, selectionIndex + lengthAfterSelectionIndex);
|
||||
const lineOffset = activeLineStart;
|
||||
|
||||
const terms = getTermContexts(targetQuery);
|
||||
const searchIndex = selectionIndex - lineOffset;
|
||||
const term = terms.find(([range]) => range[0] < searchIndex && range[1] >= searchIndex) ?? null;
|
||||
|
||||
// Converting line-specific indexes back to absolute ones.
|
||||
if (isMultiline && term) {
|
||||
if (term) {
|
||||
const [range] = term;
|
||||
|
||||
range[0] += lineOffset;
|
||||
|
|
Loading…
Reference in a new issue