Implement 'Cmd+W with no open tabs closes the window', with a setting (#11989)
Follow up to: https://github.com/zed-industries/zed/pull/10986 However, I have set this to have a default behavior of 'auto': matching the current platform's conventions, rather than a default value of 'off'. fixes https://github.com/zed-industries/zed/issues/5322. Release Notes: - Changed the behavior of `workspace::CloseActiveItem`: when you're using macOS and there are no open tabs, it now closes the window ([#5322](https://github.com/zed-industries/zed/issues/5322)). This can be controlled with a new setting, `when_closing_with_no_tabs`, to disable it on macOS, or enable it on other platforms.
This commit is contained in:
parent
7fd736e23c
commit
11c97a396e
3 changed files with 45 additions and 1 deletions
|
@ -84,6 +84,15 @@
|
||||||
"restore_on_startup": "last_workspace",
|
"restore_on_startup": "last_workspace",
|
||||||
// Size of the drop target in the editor.
|
// Size of the drop target in the editor.
|
||||||
"drop_target_size": 0.2,
|
"drop_target_size": 0.2,
|
||||||
|
// Whether the window should be closed when using 'close active item' on a window with no tabs.
|
||||||
|
// May take 3 values:
|
||||||
|
// 1. Use the current platform's convention
|
||||||
|
// "when_closing_with_no_tabs": "platform_default"
|
||||||
|
// 2. Always close the window:
|
||||||
|
// "when_closing_with_no_tabs": "close_window",
|
||||||
|
// 3. Never close the window
|
||||||
|
// "when_closing_with_no_tabs": "keep_window_open",
|
||||||
|
"when_closing_with_no_tabs": "platform_default",
|
||||||
// Whether the cursor blinks in the editor.
|
// Whether the cursor blinks in the editor.
|
||||||
"cursor_blink": true,
|
"cursor_blink": true,
|
||||||
// How to highlight the current line in the editor.
|
// How to highlight the current line in the editor.
|
||||||
|
|
|
@ -5,7 +5,7 @@ use crate::{
|
||||||
},
|
},
|
||||||
toolbar::Toolbar,
|
toolbar::Toolbar,
|
||||||
workspace_settings::{AutosaveSetting, TabBarSettings, WorkspaceSettings},
|
workspace_settings::{AutosaveSetting, TabBarSettings, WorkspaceSettings},
|
||||||
NewCenterTerminal, NewFile, NewSearch, OpenInTerminal, OpenTerminal, OpenVisible,
|
CloseWindow, NewCenterTerminal, NewFile, NewSearch, OpenInTerminal, OpenTerminal, OpenVisible,
|
||||||
SplitDirection, ToggleZoom, Workspace,
|
SplitDirection, ToggleZoom, Workspace,
|
||||||
};
|
};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
@ -948,6 +948,14 @@ impl Pane {
|
||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
) -> Option<Task<Result<()>>> {
|
) -> Option<Task<Result<()>>> {
|
||||||
if self.items.is_empty() {
|
if self.items.is_empty() {
|
||||||
|
// Close the window when there's no active items to close, if configured
|
||||||
|
if WorkspaceSettings::get_global(cx)
|
||||||
|
.when_closing_with_no_tabs
|
||||||
|
.should_close()
|
||||||
|
{
|
||||||
|
cx.dispatch_action(Box::new(CloseWindow));
|
||||||
|
}
|
||||||
|
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let active_item_id = self.items[self.active_item_index].item_id();
|
let active_item_id = self.items[self.active_item_index].item_id();
|
||||||
|
|
|
@ -13,6 +13,29 @@ pub struct WorkspaceSettings {
|
||||||
pub autosave: AutosaveSetting,
|
pub autosave: AutosaveSetting,
|
||||||
pub restore_on_startup: RestoreOnStartupBehaviour,
|
pub restore_on_startup: RestoreOnStartupBehaviour,
|
||||||
pub drop_target_size: f32,
|
pub drop_target_size: f32,
|
||||||
|
pub when_closing_with_no_tabs: CloseWindowWhenNoItems,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Default, Serialize, Deserialize, JsonSchema)]
|
||||||
|
#[serde(rename_all = "snake_case")]
|
||||||
|
pub enum CloseWindowWhenNoItems {
|
||||||
|
/// Match platform conventions by default, so "on" on macOS and "off" everywhere else
|
||||||
|
#[default]
|
||||||
|
PlatformDefault,
|
||||||
|
/// Close the window when there are no tabs
|
||||||
|
CloseWindow,
|
||||||
|
/// Leave the window open when there are no tabs
|
||||||
|
KeepWindowOpen,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CloseWindowWhenNoItems {
|
||||||
|
pub fn should_close(&self) -> bool {
|
||||||
|
match self {
|
||||||
|
CloseWindowWhenNoItems::PlatformDefault => cfg!(target_os = "macos"),
|
||||||
|
CloseWindowWhenNoItems::CloseWindow => true,
|
||||||
|
CloseWindowWhenNoItems::KeepWindowOpen => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Default, Serialize, Deserialize, JsonSchema)]
|
#[derive(Copy, Clone, Default, Serialize, Deserialize, JsonSchema)]
|
||||||
|
@ -56,6 +79,10 @@ pub struct WorkspaceSettingsContent {
|
||||||
///
|
///
|
||||||
/// Default: `0.2` (20% of the smaller dimension of the workspace)
|
/// Default: `0.2` (20% of the smaller dimension of the workspace)
|
||||||
pub drop_target_size: Option<f32>,
|
pub drop_target_size: Option<f32>,
|
||||||
|
/// Whether to close the window when using 'close active item' on a workspace with no tabs
|
||||||
|
///
|
||||||
|
/// Default: auto ("on" on macOS, "off" otherwise)
|
||||||
|
pub when_closing_with_no_tabs: Option<CloseWindowWhenNoItems>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue