forked from cline/cline
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
fix: preserve viewport position when applying diffs to active editor #8613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
heyseth
wants to merge
3
commits into
RooCodeInc:main
Choose a base branch
from
heyseth:fix/preserve-viewport-when-applying-diffs-to-the-active-editor-avoid-reopen
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
fix: preserve viewport position when applying diffs to active editor #8613
heyseth
wants to merge
3
commits into
RooCodeInc:main
from
heyseth:fix/preserve-viewport-when-applying-diffs-to-the-active-editor-avoid-reopen
Conversation
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
Fixes RooCodeInc#8112 When Roo edits a file that's currently open, the viewport now stays at the user's original scroll position instead of jumping to the top. This prevents workflow disruption during file edits. Changes: - Added originalViewportRanges and originalViewColumn properties to DiffViewProvider to capture viewport state before opening diff view - Modified open() to capture viewport position before closing the original file tab - Updated saveChanges() to restore exact viewport by revealing the middle line of the original visible range - Updated revertChanges() to preserve viewport when reverting changes - Updated saveDirectly() to capture and restore viewport for PREVENT_FOCUS_DISRUPTION experiment - Modified reset() to clear viewport state The fix uses the middle line of the original visible range with InCenter reveal type, which accurately reconstructs the viewport.
The setTimeout in viewport restoration introduced an unnecessary race condition when reopening editors. Since showTextDocument() already returns the TextEditor reference, we now use that directly instead of searching for the editor again after a delay.
Removed unnecessary editor searches using vscode.window.visibleTextEditors.find() after showTextDocument() calls. Since showTextDocument() already returns the TextEditor reference, we can use it directly for viewport restoration instead of searching for the editor again. This change applies to both the acceptDiff() and rejectDiff() code paths, making viewport restoration more reliable and eliminating potential race conditions where the editor might not be immediately available in the visibleTextEditors array.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
bug
Something isn't working
PR - Needs Preliminary Review
size:M
This PR changes 30-99 lines, ignoring generated files.
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.
Related GitHub Issue
Closes: #8112
Description
This PR fixes the viewport jumping issue when Roo edits a file that's currently open. Previously, the editor would reset to the top of the file or scroll to the edited lines, breaking the user's workflow. Now the exact scroll position is preserved throughout the edit process.
Implementation approach:
open()method before the original file tab is closed and the diff view is opened. This ensures we have the true pre-edit viewport state.originalViewportRanges: The visible line ranges in the editororiginalViewColumn: Which column/pane the editor was inTextEditorRevealType.InCenter.saveChanges(): Normal diff view workflowrevertChanges(): When user rejects changessaveDirectly(): PREVENT_FOCUS_DISRUPTION experiment path (no diff view)Test Procedure
Autosave changes viewport test:
Manual save changes viewport test:
Manual revert changes viewport test:
New file creation viewport test:
PREVENT_FOCUS_DISRUPTION experiment:
saveDirectly()path)Pre-Submission Checklist
Documentation Updates
Additional Notes
Get in Touch
Discord:
@ocean.smithImportant
Preserve editor viewport position when applying diffs in
DiffViewProviderby capturing and restoring viewport state.DiffViewProviderwhen applying diffs to active editor.visibleRangesandviewColumninopen()before closing original tab.TextEditorRevealType.InCenterinsaveChanges(),revertChanges(), andsaveDirectly().originalViewportRangesandoriginalViewColumnproperties to store viewport state.open(),saveChanges(),revertChanges(), andsaveDirectly()to handle viewport restoration.This description was created by
for fac6fba. You can customize this summary. It will automatically update as commits are pushed.