Improve workspace bindings (#33765)

* Add a "close item"-like binding to close the active dock, if present

Now, cmd/ctrl-w can be used close the focused dock before the Zed window

* Add defaults to MoveItem* actions to make it appear in the command
palette

Release Notes:

- N/A
This commit is contained in:
Kirill Bulatov 2025-07-02 23:31:32 +03:00 committed by GitHub
parent 64c413b9b6
commit f27b508e4b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 28 additions and 4 deletions

View file

@ -605,7 +605,9 @@
// "foo-bar": ["task::Spawn", { "task_name": "MyTask", "reveal_target": "dock" }]
// or by tag:
// "foo-bar": ["task::Spawn", { "task_tag": "MyTag" }],
"f5": "debugger::Rerun"
"f5": "debugger::Rerun",
"ctrl-f4": "workspace::CloseActiveDock",
"ctrl-w": "workspace::CloseActiveDock"
}
},
{

View file

@ -659,7 +659,8 @@
"cmd-k shift-up": "workspace::SwapPaneUp",
"cmd-k shift-down": "workspace::SwapPaneDown",
"cmd-shift-x": "zed::Extensions",
"f5": "debugger::Rerun"
"f5": "debugger::Rerun",
"cmd-w": "workspace::CloseActiveDock"
}
},
{

View file

@ -103,6 +103,7 @@ pub struct ActivateItem(pub usize);
#[action(namespace = pane)]
#[serde(deny_unknown_fields)]
pub struct CloseActiveItem {
#[serde(default)]
pub save_intent: Option<SaveIntent>,
#[serde(default)]
pub close_pinned: bool,
@ -112,6 +113,7 @@ pub struct CloseActiveItem {
#[action(namespace = pane)]
#[serde(deny_unknown_fields)]
pub struct CloseInactiveItems {
#[serde(default)]
pub save_intent: Option<SaveIntent>,
#[serde(default)]
pub close_pinned: bool,
@ -121,6 +123,7 @@ pub struct CloseInactiveItems {
#[action(namespace = pane)]
#[serde(deny_unknown_fields)]
pub struct CloseAllItems {
#[serde(default)]
pub save_intent: Option<SaveIntent>,
#[serde(default)]
pub close_pinned: bool,

View file

@ -224,6 +224,7 @@ pub struct ActivatePane(pub usize);
#[action(namespace = workspace)]
#[serde(deny_unknown_fields)]
pub struct MoveItemToPane {
#[serde(default = "default_1")]
pub destination: usize,
#[serde(default = "default_true")]
pub focus: bool,
@ -231,10 +232,15 @@ pub struct MoveItemToPane {
pub clone: bool,
}
fn default_1() -> usize {
1
}
#[derive(Clone, Deserialize, PartialEq, JsonSchema, Action)]
#[action(namespace = workspace)]
#[serde(deny_unknown_fields)]
pub struct MoveItemToPaneInDirection {
#[serde(default = "default_right")]
pub direction: SplitDirection,
#[serde(default = "default_true")]
pub focus: bool,
@ -242,10 +248,15 @@ pub struct MoveItemToPaneInDirection {
pub clone: bool,
}
fn default_right() -> SplitDirection {
SplitDirection::Right
}
#[derive(Clone, PartialEq, Debug, Deserialize, JsonSchema, Action)]
#[action(namespace = workspace)]
#[serde(deny_unknown_fields)]
pub struct SaveAll {
#[serde(default)]
pub save_intent: Option<SaveIntent>,
}
@ -253,6 +264,7 @@ pub struct SaveAll {
#[action(namespace = workspace)]
#[serde(deny_unknown_fields)]
pub struct Save {
#[serde(default)]
pub save_intent: Option<SaveIntent>,
}
@ -260,6 +272,7 @@ pub struct Save {
#[action(namespace = workspace)]
#[serde(deny_unknown_fields)]
pub struct CloseAllItemsAndPanes {
#[serde(default)]
pub save_intent: Option<SaveIntent>,
}
@ -267,6 +280,7 @@ pub struct CloseAllItemsAndPanes {
#[action(namespace = workspace)]
#[serde(deny_unknown_fields)]
pub struct CloseInactiveTabsAndPanes {
#[serde(default)]
pub save_intent: Option<SaveIntent>,
}
@ -2806,12 +2820,14 @@ impl Workspace {
})
}
fn close_active_dock(&mut self, window: &mut Window, cx: &mut Context<Self>) {
fn close_active_dock(&mut self, window: &mut Window, cx: &mut Context<Self>) -> bool {
if let Some(dock) = self.active_dock(window, cx) {
dock.update(cx, |dock, cx| {
dock.set_open(false, window, cx);
});
return true;
}
false
}
pub fn close_all_docks(&mut self, window: &mut Window, cx: &mut Context<Self>) {
@ -5450,7 +5466,9 @@ impl Workspace {
))
.on_action(cx.listener(
|workspace: &mut Workspace, _: &CloseActiveDock, window, cx| {
workspace.close_active_dock(window, cx);
if !workspace.close_active_dock(window, cx) {
cx.propagate();
}
},
))
.on_action(