From 780e8a77c3327c87b4f9b640820b6a2e9974b7ec Mon Sep 17 00:00:00 2001 From: Oliver Blanthorn Date: Mon, 25 May 2020 09:25:56 +0100 Subject: [PATCH] Move focus cache out of loop --- src/content/scrolling.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/content/scrolling.ts b/src/content/scrolling.ts index e28cafb1..07e64cbf 100644 --- a/src/content/scrolling.ts +++ b/src/content/scrolling.ts @@ -185,6 +185,9 @@ export async function recursiveScroll( // If that didn't work, go on to recursive scroll node = document.documentElement + + // Invalidate the cache if the user changes focus + lastFocused = document.activeElement } } let treeWalker = document.createTreeWalker(node, NodeFilter.SHOW_ELEMENT) @@ -202,7 +205,6 @@ export async function recursiveScroll( ) { // Cache the node for next time and stop trying to scroll lastRecursiveScrolled = treeWalker.currentNode - lastFocused = document.activeElement // Invalidate the cache if the user changes focus lastX = xDistance lastY = yDistance return true