-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: resolve diff editor issues with markdown preview associations (#4946) #4980
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
Merged
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
…4946) - Pre-open files as text documents before executing diff command to avoid preview mode - Update closeAllDiffViews to identify diff tabs by label pattern - Add comprehensive tests for the new behavior This ensures that files with custom editor associations (like markdown preview) can be properly edited using Roo Code's diff editor tools.
mrubens
reviewed
Jun 21, 2025
mrubens
approved these changes
Jun 21, 2025
Collaborator
mrubens
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good other than the comment about using a constant for Original ↔ Roo's Changes and looking for that
- Add DIFF_VIEW_LABEL_SEPARATOR constant to prevent breaking logic if string changes - Update all usages in DiffViewProvider.ts and test file - Addresses PR review feedback for better maintainability
- Rename DIFF_VIEW_LABEL_SEPARATOR to DIFF_VIEW_LABEL_CHANGES - Include full 'Original ↔ Roo's Changes' text in constant for better maintainability - Update all usages in DiffViewProvider.ts and test file - Addresses feedback to make constant changes less awkward
mrubens
approved these changes
Jun 22, 2025
cte
pushed a commit
that referenced
this pull request
Jun 24, 2025
…4946) (#4980) * fix: resolve diff editor issues with markdown preview associations (#4946) - Pre-open files as text documents before executing diff command to avoid preview mode - Update closeAllDiffViews to identify diff tabs by label pattern - Add comprehensive tests for the new behavior This ensures that files with custom editor associations (like markdown preview) can be properly edited using Roo Code's diff editor tools. * refactor: extract diff view label separator as shared constant - Add DIFF_VIEW_LABEL_SEPARATOR constant to prevent breaking logic if string changes - Update all usages in DiffViewProvider.ts and test file - Addresses PR review feedback for better maintainability * refactor: improve diff view label constant to include full text - Rename DIFF_VIEW_LABEL_SEPARATOR to DIFF_VIEW_LABEL_CHANGES - Include full 'Original ↔ Roo's Changes' text in constant for better maintainability - Update all usages in DiffViewProvider.ts and test file - Addresses feedback to make constant changes less awkward
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
bug
Something isn't working
lgtm
This PR has been approved by a maintainer
PR - Needs Review
size:L
This PR changes 100-499 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.
Description
Fixes #2360
This PR resolves an issue where file editing tools (apply_diff, write_to_file, search_and_replace) fail for files that have custom editor associations configured in VS Code, particularly markdown files with preview mode associations.
Root Cause
When VS Code has
workbench.editorAssociationsconfigured to open certain file types (like"*.md": "vscode.markdown.preview.editor"), thevscode.diffcommand opens the file in preview mode instead of as an editable text document. This causes:Solution
Implemented a simple and reliable approach:
vscode.window.showTextDocument()withpreview: falseto ensure the file opens in text editing modecloseAllDiffViews()to identify diff tabs both by URI scheme and by label pattern ("↔ Roo's Changes")This PR doesn't affect the normal behavior of editing files at all. Files were being opened when edited, but this happened after the edit itself. Now it happens before the edit. Ultimately, the result is exactly the same.
Changes Made
src/integrations/editor/DiffViewProvider.ts:openDiffEditor()to pre-open files as text documents before executing diff commandcloseAllDiffViews()to detect diff views by label pattern as fallbacksrc/integrations/editor/__tests__/DiffViewProvider.spec.ts:Testing
Verification of Acceptance Criteria
Impact
showTextDocumentcall per diff operationScreenshots/Demo
Before: File editing tools would fail with "Illegal value for lineNumber" errors for markdown files with preview associations.
After: File editing tools work seamlessly regardless of editor associations.
Checklist
Important
Fixes diff editor issues in VS Code by pre-opening files as text documents and enhancing diff view detection.
vscode.diffcommand opening files in preview mode due toworkbench.editorAssociations.vscode.window.showTextDocument()withpreview: false.closeAllDiffViews()inDiffViewProvider.tsto detect diff views by URI scheme and label pattern.DiffViewProvider.spec.tsto mock necessary VSCode APIs.This description was created by
for 7909ee1. You can customize this summary. It will automatically update as commits are pushed.