From 785b593bc4c407074bfebd36dcb6185f07437fe7 Mon Sep 17 00:00:00 2001 From: gholk Date: Sat, 17 Sep 2022 22:25:37 +0800 Subject: [PATCH] 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. --- src/content/finding.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/content/finding.ts b/src/content/finding.ts index ed48d587..92901f1e 100644 --- a/src/content/finding.ts +++ b/src/content/finding.ts @@ -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