fix(editor): a document closed with changes no longer counts as unsaved (#4196)

Closing a modified document with Don't Save left the backend dirty flag set, so the exit guard asked about it again on Exit. The document store now reports a buffer clean when it is closed.

Fixes #4118
This commit is contained in:
l0ng-ai
2026-11-18 16:54:23 +08:00
committed by GitHub
parent b921de184b
commit 2fe09e73f5
2 changed files with 12 additions and 0 deletions
+2
View File
@@ -653,6 +653,8 @@ impl Documents {
};
let mut st = slot.lock();
st.closed = true;
// A buffer closed with changes (Don't Save) has nothing left to save.
self.set_dirty(doc, &mut st, false);
if st.observed {
for o in self.observers() {
o.closed(doc, &st.path);
+10
View File
@@ -228,6 +228,16 @@ fn dirty_events(events: &[IdeEvent]) -> Vec<bool> {
events.iter().filter_map(|e| if let IdeEvent::DocDirty { dirty, .. } = e { Some(*dirty) } else { None }).collect()
}
#[test]
fn closing_a_modified_buffer_reports_it_clean() {
let f = fixture();
let info = f.docs.open_untitled(None).unwrap();
f.docs.edit(info.id, 0, change(0, 0, "draft")).unwrap();
assert_eq!(dirty_events(&f.events.lock()), vec![true]);
f.docs.close(info.id);
assert_eq!(dirty_events(&f.events.lock()), vec![true, false]);
}
#[test]
fn open_edit_save_close() {
let f = fixture();