Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Don't save deleted files (#24171)

Conrad Irwin9a22ef2fd545
diff --git a/crates/git_ui/src/project_diff.rs b/crates/git_ui/src/project_diff.rs
index a9dd2bd3880..8d8b0255628 100644
--- a/crates/git_ui/src/project_diff.rs
+++ b/crates/git_ui/src/project_diff.rs
@@ -27,7 +27,7 @@ use workspace::{
use crate::git_panel::GitPanel;
-actions!(git, [ShowUncommittedChanges]);
+actions!(git, [Diff]);
pub(crate) struct ProjectDiff {
multibuffer: Entity<MultiBuffer>,
@@ -63,7 +63,7 @@ impl ProjectDiff {
fn deploy(
workspace: &mut Workspace,
- _: &ShowUncommittedChanges,
+ _: &Diff,
window: &mut Window,
cx: &mut Context<Workspace>,
) {
diff --git a/crates/language/src/buffer.rs b/crates/language/src/buffer.rs
index b47e2ba78b1..dc6399122c9 100644
--- a/crates/language/src/buffer.rs
+++ b/crates/language/src/buffer.rs
@@ -1914,12 +1914,17 @@ impl Buffer {
/// Checks if the buffer has unsaved changes.
pub fn is_dirty(&self) -> bool {
- self.capability != Capability::ReadOnly
- && (self.has_conflict
- || self.file.as_ref().map_or(false, |file| {
- matches!(file.disk_state(), DiskState::New | DiskState::Deleted)
- })
- || self.has_unsaved_edits())
+ if self.capability == Capability::ReadOnly {
+ return false;
+ }
+ if self.has_conflict || self.has_unsaved_edits() {
+ return true;
+ }
+ match self.file.as_ref().map(|f| f.disk_state()) {
+ Some(DiskState::New) => !self.is_empty(),
+ Some(DiskState::Deleted) => true,
+ _ => false,
+ }
}
/// Checks if the buffer and its file have both changed since the buffer