From ec211e018b6d8d5d37b4bb312d96542433f0d075 Mon Sep 17 00:00:00 2001 From: Jaifroid Date: Mon, 6 Jan 2025 09:50:20 +0000 Subject: [PATCH] Fix search with zoom --- www/js/lib/util.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/www/js/lib/util.js b/www/js/lib/util.js index 862d310c5..de8811aa5 100644 --- a/www/js/lib/util.js +++ b/www/js/lib/util.js @@ -1,4 +1,4 @@ -/** +/** * util.js : Utility functions * * Copyright 2013-2023 Mossroy, Jaifroid and contributors @@ -487,7 +487,13 @@ function Hilitor (node, tag) { if (appstate.isReplayWorkerAvailable) { iframeWindow = document.getElementById('articleContent').contentDocument.getElementById('replay_iframe').contentWindow; } - var scrollOffset = hilitedNodes[start].offsetTop - window.innerHeight / 4; + var root = iframeWindow.document.documentElement; + var zoomFactor = 'zoom' in root.style && params.relativeFontSize && !window.MSBlobBuilder + ? params.relativeFontSize / 100 : 1; + // Convert both the element position and viewport height to zoomed coordinates + var elementPosition = hilitedNodes[start].offsetTop * zoomFactor; + var viewportOffset = window.innerHeight / 4; + var scrollOffset = elementPosition - viewportOffset; if ('scrollBehavior' in document.documentElement.style) { iframeWindow.scrollTo({ top: scrollOffset,