Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions src/renderer/src/components/file-annotator/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,23 @@ export default function FileAnnotator({ file, isAnnotable = false }: Props) {
if (!activeSearchMatchId) return;

const timer = window.setTimeout(() => {
const element = document.querySelector<HTMLElement>(
`[data-search-match-id="${activeSearchMatchId}"]`,
);
element?.scrollIntoView({
const container = fileRef.current;
const element = Array.from(
container?.querySelectorAll<HTMLElement>("[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,
Comment on lines +187 to +188

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question (bug_risk): Dropping horizontal scroll alignment may change behavior for horizontally scrollable content.

Previously, scrollIntoView({ inline: "nearest" }) could adjust horizontal scroll for overflowed content. Now we only scroll vertically via top, so matches near the left/right edges may remain partially hidden in horizontally scrollable annotators. If horizontal overflow can occur here, consider adding horizontal alignment or confirm that this behavior change is acceptable.

behavior: "smooth",
block: "center",
inline: "nearest",
});
}, 50);

Expand Down