mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 08:03:19 +00:00
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:
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user