buffer: Reload after undo when file changed while dirty#51037
Merged
probably-neb merged 2 commits intozed-industries:mainfrom Mar 10, 2026
Merged
buffer: Reload after undo when file changed while dirty#51037probably-neb merged 2 commits intozed-industries:mainfrom
probably-neb merged 2 commits intozed-industries:mainfrom
Conversation
When a buffer is dirty and an external tool writes to the file, `file_updated()` correctly updates the file metadata but suppresses `ReloadNeeded` because the buffer has unsaved edits. If the user then undoes all edits, the buffer becomes clean but still shows the old content while the disk has newer content. Fix: in `did_edit()`, after detecting a dirty-to-clean transition, check if the file's disk mtime differs from the buffer's saved mtime. If so, emit `ReloadNeeded` to trigger a reload from disk. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Collaborator
|
Seems like a rare case, but the fix and issue both make sense. Thanks! |
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.
Closes #48697
Supersedes #48698
Related to #38109
Problem
If you edit a file and an external tool writes to it while you have unsaved changes, Zed tracks the new file but skips the reload to preserve your edits. If you then undo everything, the buffer goes back to clean but still shows the old content. The disk has moved on, but nothing triggers a reload.
Fix
In
did_edit(), when the buffer transitions from dirty to clean, check if the file's mtime changed while it was dirty. If so, emitReloadNeeded. Only fires for files that still exist on disk (DiskState::Present).7 lines in
crates/language/src/buffer.rs.No double reload
file_updated()suppressesReloadNeededwhen the buffer is dirty (that's the whole bug). So by the timedid_edit()fires on dirty-to-clean, no prior reload was emitted for this file change. The two paths are mutually exclusive.Test plan
test_dirty_buffer_reloads_after_undotest_buffer_is_dirtyor other buffer testsRelease Notes: