Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Improve workspace bindings (#33765)

Kirill Bulatovf27b508e4bec
diff --git a/assets/keymaps/default-linux.json b/assets/keymaps/default-linux.json
index f0ed829c1ec..6f509458288 100644
--- a/assets/keymaps/default-linux.json
+++ b/assets/keymaps/default-linux.json
@@ -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"
}
},
{
diff --git a/assets/keymaps/default-macos.json b/assets/keymaps/default-macos.json
index cd986e12e9c..71b7a397896 100644
--- a/assets/keymaps/default-macos.json
+++ b/assets/keymaps/default-macos.json
@@ -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"
}
},
{
diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rs
index cb2dd99f5e6..b002d3ebe73 100644
--- a/crates/workspace/src/pane.rs
+++ b/crates/workspace/src/pane.rs
@@ -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,
diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs
index d31a7831ee4..95e0a4aa686 100644
--- a/crates/workspace/src/workspace.rs
+++ b/crates/workspace/src/workspace.rs
@@ -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(