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 <conrad.irwin@gmail.com>
This commit is contained in:
João Miguel Nogueira 2024-05-12 22:18:30 +01:00 committed by GitHub
parent 9fdfe5c813
commit 78f1482cd1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 1 deletions

View File

@ -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:
//

View File

@ -1404,8 +1404,15 @@ impl Pane {
project: Model<Project>,
cx: &mut WindowContext,
) -> Task<Result<()>> {
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(()))
}