Require save confirmation and prevent autosave for deleted files (#20742)
* `has_conflict` will now return true if the file has been deleted on disk. This is for treating multi-buffers as conflicted, and also blocks auto-save. * `has_deleted_file` is added so that the single-file buffer save can specifically mention the delete conflict. This does not yet handle discard (#20745). Closes #9101 Closes #9568 Closes #20462 Release Notes: - Improved handling of externally deleted files: auto-save will be disabled, multibuffers will treat this as a save conflict, and single buffers will ask for restore confirmation. Co-authored-by: Conrad <conrad@zed.dev>
This commit is contained in:
parent
ac5ecf5487
commit
369828f51c
6 changed files with 93 additions and 27 deletions
|
@ -1749,13 +1749,20 @@ impl Buffer {
|
|||
.map_or(false, |file| file.is_deleted() || !file.is_created()))
|
||||
}
|
||||
|
||||
pub fn is_deleted(&self) -> bool {
|
||||
self.file.as_ref().map_or(false, |file| file.is_deleted())
|
||||
}
|
||||
|
||||
/// Checks if the buffer and its file have both changed since the buffer
|
||||
/// was last saved or reloaded.
|
||||
pub fn has_conflict(&self) -> bool {
|
||||
self.has_conflict
|
||||
|| self.file.as_ref().map_or(false, |file| {
|
||||
file.mtime() > self.saved_mtime && self.has_unsaved_edits()
|
||||
})
|
||||
if self.has_conflict {
|
||||
return true;
|
||||
}
|
||||
let Some(file) = self.file.as_ref() else {
|
||||
return false;
|
||||
};
|
||||
file.is_deleted() || (file.mtime() > self.saved_mtime && self.has_unsaved_edits())
|
||||
}
|
||||
|
||||
/// Gets a [`Subscription`] that tracks all of the changes to the buffer's text.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue