Repository navigation
diff: Add line_bounds, viewport_bounds and top_file, and notify on scroll - #4019
Closed
sam-phinizy wants to merge 1 commit into
Closed
sam-phinizy wants to merge 1 commit into
sam-phinizy wants to merge 1 commit into
Conversation
… on scroll Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
|
💡 Needs the maintainer's call: three new public read-only queries on Reviewed at f505427..01e3f45 (head
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
An application that puts its own content beside a diff's lines — a floating comment card next to the lines it's about, a marker following a line as the diff scrolls — needs to know where those lines are on screen, and to hear when that changes.
DiffStatekeeps the list's layout to itself, so today the only way is to fork the component.This adds read-only position queries and notifies the state's observers when the diff scrolls, so an observer can re-place its content:
line_bounds— where a source line is laid out now, orNonewhen it isn't (outside the rendered range, folded, or in a collapsed file).viewport_bounds— the part of the diff on screen, to keep placed content inside it.top_file— the path of the file at the top of the viewport, for "this file" commands (mark viewed, copy path) that should act on what's being read rather than on the last file clicked.We've been carrying these as a local patch in a code-review app, for floating comment cards and a guided tour that follow their lines.
Public API
gpui_component(diff::DiffState):pub fn line_bounds(&self, position: &DiffLinePosition) -> Option<Bounds<Pixels>>— where a source line is laid out now, in window coordinates;Nonewhen it isn't laid out.pub fn viewport_bounds(&self) -> Bounds<Pixels>— the visible part of the diff, in window coordinates.pub fn top_file(&self) -> Option<SharedString>— the path of the file at the top of the viewport.Behaviour:
DiffStatenow callscx.notify()when its list scrolls, socx.observe(&state, …)hears scrolling.How to Test
cargo test -p gpui-component --lib diff::— addsa_line_scrolled_to_has_bounds_inside_the_viewport_and_names_the_top_fileindiff/scroll_tests.rs: a line isn't laid out before it's scrolled to, is inside the viewport after, and the top file is named.Checklist
cargo runfor story tests related to the changes. (No story change; covered by the test above.)🤖 Generated with Claude Code