From ac09374781ceca7060b008ec2e86ecb2ea4f8c6d Mon Sep 17 00:00:00 2001 From: Brendan Kellam Date: Mon, 23 Mar 2026 21:52:22 -0700 Subject: [PATCH 1/2] fix(web): fix scroll position for references further down in a file Uses lineBlockAt() instead of coordsAtPos() to get line positions from CodeMirror's internal height map, which works correctly for virtualized lines that haven't been rendered yet. Co-Authored-By: Claude Sonnet 4.6 --- .../chatThread/referencedSourcesListView.tsx | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/packages/web/src/features/chat/components/chatThread/referencedSourcesListView.tsx b/packages/web/src/features/chat/components/chatThread/referencedSourcesListView.tsx index 8ceecaad0..5f12c6f54 100644 --- a/packages/web/src/features/chat/components/chatThread/referencedSourcesListView.tsx +++ b/packages/web/src/features/chat/components/chatThread/referencedSourcesListView.tsx @@ -114,11 +114,6 @@ const ReferencedSourcesListViewComponent = ({ scrollAreaViewport && selectedReference.range.startLine <= editorRef.view.state.doc.lines ) { - const view = editorRef.view; - const lineNumber = selectedReference.range.startLine; - - const pos = view.state.doc.line(lineNumber).from; - // Expand the file if it's collapsed. setCollapsedFileIds((collapsedFileIds) => collapsedFileIds.filter((id) => id !== fileId)); @@ -139,15 +134,26 @@ const ReferencedSourcesListViewComponent = ({ behavior: 'instant', }); + const view = editorRef.view; + const lineNumber = selectedReference.range.startLine; + requestAnimationFrame(() => { - const coords = view.coordsAtPos(pos); - if (!coords) { - return; - } + // Get the line's position within the CodeMirror document + const pos = view.state.doc.line(lineNumber).from; + const blockInfo = view.lineBlockAt(pos); + const lineTopInCodeMirror = blockInfo.top; + // Get the bounds of both elements const viewportRect = scrollAreaViewport.getBoundingClientRect(); - const lineTopRelativeToScrollArea = coords.top - viewportRect.top + scrollAreaViewport.scrollTop; + const codeMirrorRect = view.dom.getBoundingClientRect(); + + // Calculate the line's position relative to the ScrollArea content + const lineTopRelativeToScrollArea = lineTopInCodeMirror + (codeMirrorRect.top - viewportRect.top) + scrollAreaViewport.scrollTop; + + // Get the height of the visible ScrollArea const scrollAreaHeight = scrollAreaViewport.clientHeight; + + // Calculate the target scroll position to center the line const targetScrollTop = lineTopRelativeToScrollArea - (scrollAreaHeight / 3); scrollAreaViewport.scrollTo({ From 67e3ca173945427be2807e9ee189f2e660ac83a3 Mon Sep 17 00:00:00 2001 From: Brendan Kellam Date: Mon, 23 Mar 2026 21:53:01 -0700 Subject: [PATCH 2/2] chore: update CHANGELOG for #1036 Co-Authored-By: Claude Sonnet 4.6 --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e84db7f15..27cdf2e92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed +- Fixed scroll position when selecting chat references that point to lines further down in a file. [#1036](https://github.com/sourcebot-dev/sourcebot/pull/1036) + ## [4.16.0] - 2026-03-24 ### Changed