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 https://github.com/zed-industries/zed/issues/47968. Supersedes https://github.com/zed-industries/zed/pull/51801 and https://github.com/zed-industries/zed/pull/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>
43 lines
1.1 KiB
Rust
43 lines
1.1 KiB
Rust
//! Contains the [`VimModeSetting`] and [`HelixModeSetting`] used to enable/disable Vim and Helix modes.
|
|
//!
|
|
//! This is in its own crate as we want other crates to be able to enable or
|
|
//! disable Vim/Helix modes without having to depend on the `vim` crate in its
|
|
//! entirety.
|
|
|
|
use gpui::App;
|
|
use settings::{RegisterSetting, Settings, SettingsContent};
|
|
|
|
#[derive(RegisterSetting)]
|
|
pub struct VimModeSetting(pub bool);
|
|
|
|
impl Settings for VimModeSetting {
|
|
fn from_settings(content: &SettingsContent) -> Self {
|
|
Self(content.vim_mode.unwrap())
|
|
}
|
|
}
|
|
|
|
impl VimModeSetting {
|
|
pub fn is_enabled(cx: &App) -> bool {
|
|
Self::try_get(cx)
|
|
.map(|vim_mode| vim_mode.0)
|
|
.unwrap_or(false)
|
|
}
|
|
}
|
|
|
|
#[derive(RegisterSetting)]
|
|
pub struct HelixModeSetting(pub bool);
|
|
|
|
impl HelixModeSetting {
|
|
pub fn is_enabled(cx: &App) -> bool {
|
|
Self::try_get(cx)
|
|
.map(|helix_mode| helix_mode.0)
|
|
.unwrap_or(false)
|
|
}
|
|
}
|
|
|
|
impl Settings for HelixModeSetting {
|
|
fn from_settings(content: &SettingsContent) -> Self {
|
|
Self(content.helix_mode.unwrap())
|
|
}
|
|
}
|