Skip to content

Allow modals to opt out of blocking autosave#51801

Closed
mchisolm0 wants to merge 1 commit intozed-industries:mainfrom
mchisolm0:tabswitcher-trigger-autosave
Closed

Allow modals to opt out of blocking autosave#51801
mchisolm0 wants to merge 1 commit intozed-industries:mainfrom
mchisolm0:tabswitcher-trigger-autosave

Conversation

@mchisolm0
Copy link
Copy Markdown
Collaborator

@mchisolm0 mchisolm0 commented Mar 18, 2026

Currently, autosave behavior is guarded by

  1. if the item has lost focus and
  2. an unconditional check if a modal is active.

This allows the TabSwitcher to block autosave when it gains focus, preventing autosave from ever triggering for the file which lost focus.

This PR allows modals to opt out of blocking autosave, however, I am concerned having autosave trigger immediately on TabSwitcher getting focus may cause the unwanted formatting and cursor jumps mentioned in the comment above the item.rs change. I have a PR built on this one which only triggers autosave when the TabSwitcher focuses the new tab (#51802)

  • Add ModalView::blocks_focus_change_autosave with a default of true so existing modals continue to block autosave.
  • Thread the check through ModalViewHandle, ModalLayer, and Workspace and use it when deciding whether to autosave items on focus change.
  • Implement TabSwitcher to return false.

Closes #47968

Before you mark this PR as ready for review, make sure that you have:

  • Added a solid test coverage and/or screenshots from doing manual testing
  • Done a self-review taking into account security and performance aspects
  • N/A Aligned any UI changes with the UI checklist
Recording of fix
TabSwitcher.fix.with.immediate.autosave.mp4

Release Notes:

  • Fixed tab switcher not triggering autosave

- Add ModalView::blocks_focus_change_autosave with a default of true
  so existing modals continue to block autosave.
- Thread the check through ModalViewHandle, ModalLayer, and
  Workspace and use it when deciding whether to autosave items on focus
  change.
- Implement TabSwitcher to
  return false.
@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Mar 18, 2026
@zed-community-bot zed-community-bot bot added the guild Pull requests by someone in Zed Guild. NOTE: the label application is automated via github actions label Mar 18, 2026
@mchisolm0 mchisolm0 mentioned this pull request Mar 18, 2026
2 tasks
@SomeoneToIgnore SomeoneToIgnore self-assigned this Mar 19, 2026
@maxdeviant
Copy link
Copy Markdown
Member

Thanks for taking a look!

We have an alternative solution open in #51949 that we are discussing that would supersede this one.

maxdeviant added a commit that referenced this pull request Mar 19, 2026
…x command palette (#51949)

This PR adjusts the logic that was added in #45166 to just apply to the
specific case of interacting with the command palette in Vim and Helix
modes (hereafter referred to collectively as "Vim mode").

In that PR, we would suppress the auto-save on focus change for _any_
modal in the workspace, regardless of whether we were actually in Vim
mode or not. This would cause issues where moving between files some
other way—such as the tab switcher or the file finder—would cause the
buffers to never be saved.

We now only suppress the auto-save on focus loss behavior when in Vim
mode and the active modal is the command palette. In all other cases, we
save the file.

Closes #47968.

Supersedes #51801 and
#51802.

Note: the way we are identifying the active modal as the command palette
isn't the best, but @bennetbo and I didn't have any other cleaner
solutions. It's a bit tricky, as the logic lives in the `workspace`,
which isn't able to know about the `CommandPalette` due to
`command_palette` depending on `workspace`. There may be some other way
we could achieve this with more indirection, but it's unclear whether it
would be worth it at this time.

Release Notes:

- Changed `{ "autosave": "on_focus_change" }` to now always save on
focus loss, except for when activating the command palette when in
Vim/Helix mode.

Co-authored-by: Bennet Bo Fenner <bennetbo@gmx.de>
@maxdeviant
Copy link
Copy Markdown
Member

Closing in favor of #51949.

@maxdeviant maxdeviant closed this Mar 19, 2026
AmaanBilwar pushed a commit to AmaanBilwar/zed that referenced this pull request Mar 20, 2026
…x command palette (zed-industries#51949)

This PR adjusts the logic that was added in zed-industries#45166 to just apply to the
specific case of interacting with the command palette in Vim and Helix
modes (hereafter referred to collectively as "Vim mode").

In that PR, we would suppress the auto-save on focus change for _any_
modal in the workspace, regardless of whether we were actually in Vim
mode or not. This would cause issues where moving between files some
other way—such as the tab switcher or the file finder—would cause the
buffers to never be saved.

We now only suppress the auto-save on focus loss behavior when in Vim
mode and the active modal is the command palette. In all other cases, we
save the file.

Closes zed-industries#47968.

Supersedes zed-industries#51801 and
zed-industries#51802.

Note: the way we are identifying the active modal as the command palette
isn't the best, but @bennetbo and I didn't have any other cleaner
solutions. It's a bit tricky, as the logic lives in the `workspace`,
which isn't able to know about the `CommandPalette` due to
`command_palette` depending on `workspace`. There may be some other way
we could achieve this with more indirection, but it's unclear whether it
would be worth it at this time.

Release Notes:

- Changed `{ "autosave": "on_focus_change" }` to now always save on
focus loss, except for when activating the command palette when in
Vim/Helix mode.

Co-authored-by: Bennet Bo Fenner <bennetbo@gmx.de>
toshmukhamedov pushed a commit to toshmukhamedov/zed that referenced this pull request Mar 20, 2026
…x command palette (zed-industries#51949)

This PR adjusts the logic that was added in zed-industries#45166 to just apply to the
specific case of interacting with the command palette in Vim and Helix
modes (hereafter referred to collectively as "Vim mode").

In that PR, we would suppress the auto-save on focus change for _any_
modal in the workspace, regardless of whether we were actually in Vim
mode or not. This would cause issues where moving between files some
other way—such as the tab switcher or the file finder—would cause the
buffers to never be saved.

We now only suppress the auto-save on focus loss behavior when in Vim
mode and the active modal is the command palette. In all other cases, we
save the file.

Closes zed-industries#47968.

Supersedes zed-industries#51801 and
zed-industries#51802.

Note: the way we are identifying the active modal as the command palette
isn't the best, but @bennetbo and I didn't have any other cleaner
solutions. It's a bit tricky, as the logic lives in the `workspace`,
which isn't able to know about the `CommandPalette` due to
`command_palette` depending on `workspace`. There may be some other way
we could achieve this with more indirection, but it's unclear whether it
would be worth it at this time.

Release Notes:

- Changed `{ "autosave": "on_focus_change" }` to now always save on
focus loss, except for when activating the command palette when in
Vim/Helix mode.

Co-authored-by: Bennet Bo Fenner <bennetbo@gmx.de>
AmaanBilwar pushed a commit to AmaanBilwar/zed that referenced this pull request Mar 23, 2026
…x command palette (zed-industries#51949)

This PR adjusts the logic that was added in zed-industries#45166 to just apply to the
specific case of interacting with the command palette in Vim and Helix
modes (hereafter referred to collectively as "Vim mode").

In that PR, we would suppress the auto-save on focus change for _any_
modal in the workspace, regardless of whether we were actually in Vim
mode or not. This would cause issues where moving between files some
other way—such as the tab switcher or the file finder—would cause the
buffers to never be saved.

We now only suppress the auto-save on focus loss behavior when in Vim
mode and the active modal is the command palette. In all other cases, we
save the file.

Closes zed-industries#47968.

Supersedes zed-industries#51801 and
zed-industries#51802.

Note: the way we are identifying the active modal as the command palette
isn't the best, but @bennetbo and I didn't have any other cleaner
solutions. It's a bit tricky, as the logic lives in the `workspace`,
which isn't able to know about the `CommandPalette` due to
`command_palette` depending on `workspace`. There may be some other way
we could achieve this with more indirection, but it's unclear whether it
would be worth it at this time.

Release Notes:

- Changed `{ "autosave": "on_focus_change" }` to now always save on
focus loss, except for when activating the command palette when in
Vim/Helix mode.

Co-authored-by: Bennet Bo Fenner <bennetbo@gmx.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement guild Pull requests by someone in Zed Guild. NOTE: the label application is automated via github actions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inconsistent save behavior with vim mode and autosave on_focus_change

4 participants