From 78f1482cd19af29dd1a1119ad562eedd73d01a34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Miguel=20Nogueira?= <101069446+Dageus@users.noreply.github.com> Date: Sun, 12 May 2024 22:18:30 +0100 Subject: [PATCH] Add autosave with delay (#11325) Implemented autosave functionality with a delay, which now refrains from formatting the code upon triggering unless the user manually saves it. Additionally, enhanced documentation for the `format_on_save` setting has been added. This resolves the issue where autosave with delay would inadvertently format the code, disrupting the user experience, as reported in the corresponding issue. Release Notes: - Fixed a bug where autosave after_delay would auto-format the buffer ([#9787](https://github.com/zed-industries/zed/issues/9787)). --------- Co-authored-by: Conrad Irwin --- assets/settings/default.json | 2 ++ crates/workspace/src/pane.rs | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/assets/settings/default.json b/assets/settings/default.json index f78b82fd0d..14aae81617 100644 --- a/assets/settings/default.json +++ b/assets/settings/default.json @@ -349,6 +349,8 @@ // when saving it. "ensure_final_newline_on_save": true, // Whether or not to perform a buffer format before saving + // + // Keep in mind, if the autosave with delay is enabled, format_on_save will be ignored "format_on_save": "on", // How to perform a buffer format. This setting can take 4 values: // diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rs index c048bb84b8..aae840c982 100644 --- a/crates/workspace/src/pane.rs +++ b/crates/workspace/src/pane.rs @@ -1404,8 +1404,15 @@ impl Pane { project: Model, cx: &mut WindowContext, ) -> Task> { + let format = if let AutosaveSetting::AfterDelay { .. } = + WorkspaceSettings::get_global(cx).autosave + { + false + } else { + true + }; if Self::can_autosave_item(item, cx) { - item.save(true, project, cx) + item.save(format, project, cx) } else { Task::ready(Ok(())) }