Skip to content

Commit

Permalink
Add autosave with delay (#11325)
Browse files Browse the repository at this point in the history
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](#9787)).

---------

Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
  • Loading branch information
Dageus and ConradIrwin committed May 12, 2024
1 parent 9fdfe5c commit 78f1482
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions assets/settings/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -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:
//
Expand Down
9 changes: 8 additions & 1 deletion crates/workspace/src/pane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(()))
}
Expand Down

0 comments on commit 78f1482

Please sign in to comment.