Reposition all match text before find from view

If user scrolled and the match text position change, the `.top` property will
not update automatically. Then the search from view will return the wrong
match text because it make use of the old top properties.

This commit reposition (and the top properties get updated) all match text
before find the next match from the viewport.
This commit is contained in:
gholk 2022-09-17 22:25:37 +08:00
parent cbafb8077e
commit 785b593bc4

View file

@ -233,6 +233,10 @@ export function removeHighlighting() {
export function focusHighlight(index) {
lastHighlights[index].focus()
repositionHighlight()
}
export function repositionHighlight() {
for (const node of lastHighlights) {
node.updateRectsPosition()
}
@ -268,6 +272,7 @@ export async function jumpToNextMatch(n: number, searchFromView = false) {
selected =
(selected + n + lastHighlights.length) % lastHighlights.length
} else {
repositionHighlight()
const length = lastHighlights.length
const reverse = lastHighlights[length - 1].top < lastHighlights[0].top
const negative = n < 0