From 9819af06175eb074c7d424c99ff2a29390c7e534 Mon Sep 17 00:00:00 2001 From: jansaldo Date: Wed, 20 May 2026 16:48:32 -0300 Subject: [PATCH] fix(file-annotator): fix upward autoscroll on search previous navigation --- .../src/components/file-annotator/index.tsx | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/renderer/src/components/file-annotator/index.tsx b/src/renderer/src/components/file-annotator/index.tsx index 3301b478..efb80a1e 100644 --- a/src/renderer/src/components/file-annotator/index.tsx +++ b/src/renderer/src/components/file-annotator/index.tsx @@ -170,13 +170,23 @@ export default function FileAnnotator({ file, isAnnotable = false }: Props) { if (!activeSearchMatchId) return; const timer = window.setTimeout(() => { - const element = document.querySelector( - `[data-search-match-id="${activeSearchMatchId}"]`, - ); - element?.scrollIntoView({ + const container = fileRef.current; + const element = Array.from( + container?.querySelectorAll("[data-search-match-id]") ?? [], + ).find((el) => el.getAttribute("data-search-match-id") === activeSearchMatchId); + if (!element || !container) return; + + const containerRect = container.getBoundingClientRect(); + const elementRect = element.getBoundingClientRect(); + const scrollOffset = + elementRect.top - + containerRect.top - + containerRect.height / 2 + + elementRect.height / 2; + + container.scrollBy({ + top: scrollOffset, behavior: "smooth", - block: "center", - inline: "nearest", }); }, 50);