zed icon indicating copy to clipboard operation
zed copied to clipboard

Autosave when focusing other panels (terminal, project, etc)

Open vultix opened this issue 2 years ago • 4 comments

Check for existing issues

  • [X] Completed

Describe the feature

Add an option to autosave when a non-editor panel is focused, in addition to on_window_change. This is similar to how IntelliJ Idea operates by default.

Motivation

We currently have two options for autosave. There a few drawbacks I see to both of these

  • on_window_change
    • This can be frustrating with an integrated terminal - you make changes in the editor, drop down to the terminal and try running those changes, and they haven't been saved. You accidentally ran old code, which can be confusing to diagnose
    • This failure to react to changes may also apply to other panels, especially future "git" panels, "run/debug" panels, etc.
  • on_focus_change
    • It's very common to have multi-file edits. Saving on focus change can lead to premature saves, where one file is saved while the other is being edited, leaving the project in a broken state.
    • This is mostly an issue if you have an automatic build process on file save. This is common with webdev, where you "watch" changes to files to recompile and serve them.
    • The problem is exacerbated with exceptionally slow builds. I've worked in Angular projects where a rebuild takes upwards of a minute. Triggering a rebuild every time I focused another file would be untenable

If applicable, add mockups / screenshots to help present your vision of the feature

No response

vultix avatar Sep 18 '23 17:09 vultix

So you want something like "autosave": "on_focus_change_panel" and "autosave": "on_focus_change_buffer"?

By the way, in my zed there is a ~2s delay until autosave kicks in after I focus out with "autosave": "on_focus_change". A little annoying. Does this happen to you too?

htor avatar Mar 27 '24 14:03 htor

Haven’t noticed the delay myself, but I’m not using zed as my daily driver yet. Not sure of the best name. We could even call it on_window_change and have certain panels (terminal, git, etc) require the buffer be saved and be treated like a new window

vultix avatar Mar 27 '24 14:03 vultix

We currently have two options for autosave

Wait a second, WE ALREADY have such a feature in Zed? I wasn’t able to find that using fuzzy search in settings json

jerrygreen avatar Mar 27 '24 18:03 jerrygreen

I believe autosave in JetBrains or Vs code is good example how to implement it.

artemijan avatar May 20 '24 22:05 artemijan

"autosave": "on_focus_change" seems to do the job and the feature seems to be documented well here: https://zed.dev/docs/configuring-zed?highlight=Formatter#autosave @vultix @JosephTLyons I guess the issue could be closed?

EmilCataranciuc avatar Apr 18 '25 12:04 EmilCataranciuc