Autosave files on close, when setting is afterDelay (#36929)
Closes https://github.com/zed-industries/zed/issues/12149 Closes #35524 Release Notes: - Improved autosave behavior, to prevent a confirmation dialog when quickly closing files and using the `afterDelay` setting --------- Co-authored-by: MrSubidubi <finn@zed.dev>
This commit is contained in:
@@ -8737,6 +8737,36 @@ mod tests {
|
||||
cx.executor().advance_clock(Duration::from_millis(250));
|
||||
item.read_with(cx, |item, _| assert_eq!(item.save_count, 4));
|
||||
|
||||
// Autosave after delay, should save earlier than delay if tab is closed
|
||||
item.update(cx, |item, cx| {
|
||||
item.is_dirty = true;
|
||||
cx.emit(ItemEvent::Edit);
|
||||
});
|
||||
cx.executor().advance_clock(Duration::from_millis(250));
|
||||
item.read_with(cx, |item, _| assert_eq!(item.save_count, 4));
|
||||
|
||||
// // Ensure auto save with delay saves the item on close, even if the timer hasn't yet run out.
|
||||
pane.update_in(cx, |pane, window, cx| {
|
||||
pane.close_items(window, cx, SaveIntent::Close, move |id| id == item_id)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
assert!(!cx.has_pending_prompt());
|
||||
item.read_with(cx, |item, _| assert_eq!(item.save_count, 5));
|
||||
|
||||
// Add the item again, ensuring autosave is prevented if the underlying file has been deleted.
|
||||
workspace.update_in(cx, |workspace, window, cx| {
|
||||
workspace.add_item_to_active_pane(Box::new(item.clone()), None, true, window, cx);
|
||||
});
|
||||
item.update_in(cx, |item, _window, cx| {
|
||||
item.is_dirty = true;
|
||||
for project_item in &mut item.project_items {
|
||||
project_item.update(cx, |project_item, _| project_item.is_dirty = true);
|
||||
}
|
||||
});
|
||||
cx.run_until_parked();
|
||||
item.read_with(cx, |item, _| assert_eq!(item.save_count, 5));
|
||||
|
||||
// Autosave on focus change, ensuring closing the tab counts as such.
|
||||
item.update(cx, |item, cx| {
|
||||
SettingsStore::update_global(cx, |settings, cx| {
|
||||
@@ -8756,7 +8786,7 @@ mod tests {
|
||||
.await
|
||||
.unwrap();
|
||||
assert!(!cx.has_pending_prompt());
|
||||
item.read_with(cx, |item, _| assert_eq!(item.save_count, 5));
|
||||
item.read_with(cx, |item, _| assert_eq!(item.save_count, 6));
|
||||
|
||||
// Add the item again, ensuring autosave is prevented if the underlying file has been deleted.
|
||||
workspace.update_in(cx, |workspace, window, cx| {
|
||||
@@ -8770,7 +8800,7 @@ mod tests {
|
||||
window.blur();
|
||||
});
|
||||
cx.run_until_parked();
|
||||
item.read_with(cx, |item, _| assert_eq!(item.save_count, 5));
|
||||
item.read_with(cx, |item, _| assert_eq!(item.save_count, 6));
|
||||
|
||||
// Ensure autosave is prevented for deleted files also when closing the buffer.
|
||||
let _close_items = pane.update_in(cx, |pane, window, cx| {
|
||||
@@ -8778,7 +8808,7 @@ mod tests {
|
||||
});
|
||||
cx.run_until_parked();
|
||||
assert!(cx.has_pending_prompt());
|
||||
item.read_with(cx, |item, _| assert_eq!(item.save_count, 5));
|
||||
item.read_with(cx, |item, _| assert_eq!(item.save_count, 6));
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
|
||||
Reference in New Issue
Block a user