Repository navigation
diff: Add replace_files_in_place to keep the reader's place - #4020
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
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
|
💡 Small, correct, but a new public method on Head API note: a parallel entry point next to |
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
set_filesresets the viewport to the top. That's right for a different diff, but not for the same changes presented differently — the patch rebuilt with more context lines read from the files, or with whitespace-only changes left out — where jumping to the top loses the reader's place.replace_files_in_placereplaces the files likeset_files, then scrolls back to the source line that was at the top, using the same anchorset_modeandset_context_linesalready use (row_position/reveal_line).Public API
gpui_component(diff::DiffState):pub fn replace_files_in_place(&mut self, files: impl IntoIterator<Item = DiffFile>, cx: &mut Context<Self>)— replaces the files likeset_files, keeping the source line at the top of the viewport where it was.How to Test
cargo test -p gpui-component --lib diff::— addsreplacing_files_in_place_keeps_the_line_at_the_topindiff/scroll_tests.rs: scrolled to line 200 of a long patch, replacing it with the same file leaves the same row at the top.Checklist
cargo runfor story tests related to the changes. (No story change; covered by the test above.)🤖 Generated with Claude Code