Don't save deleted files (#24171)
We now treat new files that have no content as not-dirty. This fixes the git diff view when deleted files are present. It also fixes a long-standing bug where `zed RAEDME` and then closing the tab would prompt for "unsaved changes" when there were none. Release Notes: - Fixed a bug where closing an empty, named, file would warn about unsaved content.
This commit is contained in:
parent
66e0898425
commit
9a22ef2fd5
2 changed files with 13 additions and 8 deletions
|
@ -27,7 +27,7 @@ use workspace::{
|
||||||
|
|
||||||
use crate::git_panel::GitPanel;
|
use crate::git_panel::GitPanel;
|
||||||
|
|
||||||
actions!(git, [ShowUncommittedChanges]);
|
actions!(git, [Diff]);
|
||||||
|
|
||||||
pub(crate) struct ProjectDiff {
|
pub(crate) struct ProjectDiff {
|
||||||
multibuffer: Entity<MultiBuffer>,
|
multibuffer: Entity<MultiBuffer>,
|
||||||
|
@ -63,7 +63,7 @@ impl ProjectDiff {
|
||||||
|
|
||||||
fn deploy(
|
fn deploy(
|
||||||
workspace: &mut Workspace,
|
workspace: &mut Workspace,
|
||||||
_: &ShowUncommittedChanges,
|
_: &Diff,
|
||||||
window: &mut Window,
|
window: &mut Window,
|
||||||
cx: &mut Context<Workspace>,
|
cx: &mut Context<Workspace>,
|
||||||
) {
|
) {
|
||||||
|
|
|
@ -1914,12 +1914,17 @@ impl Buffer {
|
||||||
|
|
||||||
/// Checks if the buffer has unsaved changes.
|
/// Checks if the buffer has unsaved changes.
|
||||||
pub fn is_dirty(&self) -> bool {
|
pub fn is_dirty(&self) -> bool {
|
||||||
self.capability != Capability::ReadOnly
|
if self.capability == Capability::ReadOnly {
|
||||||
&& (self.has_conflict
|
return false;
|
||||||
|| self.file.as_ref().map_or(false, |file| {
|
}
|
||||||
matches!(file.disk_state(), DiskState::New | DiskState::Deleted)
|
if self.has_conflict || self.has_unsaved_edits() {
|
||||||
})
|
return true;
|
||||||
|| self.has_unsaved_edits())
|
}
|
||||||
|
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
|
/// Checks if the buffer and its file have both changed since the buffer
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue