From 057c3c1206dd8d7452c81bc9bef0e1b0650c81ab Mon Sep 17 00:00:00 2001 From: Josh Piasecki <138541977+FloppyDisco@users.noreply.github.com> Date: Mon, 20 Oct 2025 13:23:46 -0500 Subject: [PATCH] Add dock state to workspace context (#40454) I love keybindings. I spend way to much time thinking about them. I also REALLY like working in Zed. so far, however, I have found the key context system in Zed to be less flexible than in VSCode. the HUGE context that is available in VSCode helps you create keybindings for very specific targeted scenarios. the tree like structure of the Zed key context means you loose some information as focus moves throughout the application. For example, it is not currently possible to create a keybinding in the editor that will only work when one of the Docks is open, or if a specific dock is open. this would be useful in implementing solutions to ideas like #24222 we already have an action for moving focus to the dock, and we have an action for opening/closing the dock, but to my knowledge (very limited lol) we cannot determine if that dock *is open* unless we are focused on it. I think it is possible to create a more flexible key binding system by adding more context information to the higher up context ancestors. while: ``` Workspace right_dock=GitPanel Dock GitPanel Editor ``` may seem redundant, it actually communicates fundamentally different information than: ``` Workspace right_dock=GitPanel Pane Editor ``` the first says "the GitPanel is in the right hand dock AND IT IS FOCUSED", while the second means "Focus is on the Editor, and the GitPanel just happens to be open in the right hand dock" This change adds a new set of identifiers to the `Workspace` key_context that will indicate which docks are open and what is the specific panel that is currently visible in that dock. examples: - `left_dock=ProjectPanel` - `bottom_dock=TerminalPanel` - `right_dock=GitPanel` in my testing the following types of keybindings seem to be supported with this change: ```jsonc // match for any value of the identifier "context": "Workspace && bottom_dock" "context": "Workspace && !bottom_dock" // match only a specific value to an identifier "context": "Workspace && bottom_dock=TerminalPanel" // match only in a child context if the ancestor workspace has the correct identifier "context": "Workspace && !bottom_dock=DebugPanel > Editor" ``` some screen shots of the context matching in different circumstances: Screenshot 2025-10-16 at 23 20 34 Screenshot 2025-10-16 at 23 20 57 Screenshot 2025-10-16 at 23 21 37 Screenshot 2025-10-16 at 23 21 52 Screenshot 2025-10-16 at 23 22 38 the persistent_name values for `ProjectPanel` and `OutlinePanel` needed to be updated to not have a space in them in order to pass the `Identifier` check. all the other Panels already had names that did not include spaces, so it just makes these conform with the other ones. I think this is a great place to start with adding more context identifiers and i think this type of additional information will make it possible to create really dynamic keybindings! Release Notes: - Workspace key context now includes the state of the 3 docks --- crates/agent_ui/src/agent_panel.rs | 4 ++++ crates/collab_ui/src/collab_panel.rs | 4 ++++ crates/collab_ui/src/notification_panel.rs | 4 ++++ crates/debugger_ui/src/debugger_panel.rs | 6 ++++++ crates/git_ui/src/git_panel.rs | 4 ++++ crates/outline_panel/src/outline_panel.rs | 4 ++++ crates/project_panel/src/project_panel.rs | 4 ++++ crates/terminal_view/src/terminal_panel.rs | 4 ++++ crates/workspace/src/dock.rs | 10 ++++++++++ crates/workspace/src/workspace.rs | 18 ++++++++++++++++++ 10 files changed, 62 insertions(+) diff --git a/crates/agent_ui/src/agent_panel.rs b/crates/agent_ui/src/agent_panel.rs index 2def41c74dd715637f269e572342d04b944505b5..444ee22fd9098deb83614fdfc7dbd26d90783c34 100644 --- a/crates/agent_ui/src/agent_panel.rs +++ b/crates/agent_ui/src/agent_panel.rs @@ -1395,6 +1395,10 @@ impl Panel for AgentPanel { "AgentPanel" } + fn panel_key() -> &'static str { + AGENT_PANEL_KEY + } + fn position(&self, _window: &Window, cx: &App) -> DockPosition { agent_panel_dock_position(cx) } diff --git a/crates/collab_ui/src/collab_panel.rs b/crates/collab_ui/src/collab_panel.rs index e9c9c4b0fae49fc97c30bdc7697460f82043750e..bfbf9721fab6df79ddd97810fa5b1d70ee701866 100644 --- a/crates/collab_ui/src/collab_panel.rs +++ b/crates/collab_ui/src/collab_panel.rs @@ -3037,6 +3037,10 @@ impl Panel for CollabPanel { "CollabPanel" } + fn panel_key() -> &'static str { + COLLABORATION_PANEL_KEY + } + fn activation_priority(&self) -> u32 { 6 } diff --git a/crates/collab_ui/src/notification_panel.rs b/crates/collab_ui/src/notification_panel.rs index 3d988c4634ded9bd2c94d8a75886cf452e64eacb..bab4234f14ed3bba6b408efcc0170f7e15efaf50 100644 --- a/crates/collab_ui/src/notification_panel.rs +++ b/crates/collab_ui/src/notification_panel.rs @@ -612,6 +612,10 @@ impl Panel for NotificationPanel { "NotificationPanel" } + fn panel_key() -> &'static str { + NOTIFICATION_PANEL_KEY + } + fn position(&self, _: &Window, cx: &App) -> DockPosition { NotificationPanelSettings::get_global(cx).dock } diff --git a/crates/debugger_ui/src/debugger_panel.rs b/crates/debugger_ui/src/debugger_panel.rs index 093cef3630e3ae3627a2999b9deb81be3b0aeb8d..11d8683209eeac56c7f5a156c367a627e27ad459 100644 --- a/crates/debugger_ui/src/debugger_panel.rs +++ b/crates/debugger_ui/src/debugger_panel.rs @@ -43,6 +43,8 @@ use workspace::{ }; use zed_actions::ToggleFocus; +const DEBUG_PANEL_KEY: &str = "DebugPanel"; + pub struct DebugPanel { size: Pixels, active_session: Option>, @@ -1414,6 +1416,10 @@ impl Panel for DebugPanel { "DebugPanel" } + fn panel_key() -> &'static str { + DEBUG_PANEL_KEY + } + fn position(&self, _window: &Window, cx: &App) -> DockPosition { DebuggerSettings::get_global(cx).dock.into() } diff --git a/crates/git_ui/src/git_panel.rs b/crates/git_ui/src/git_panel.rs index 2e34c060f61c5dd9ed6718d379e16019c8e17b16..2678d96041b4fb1123388bbd61db904a924fc6c8 100644 --- a/crates/git_ui/src/git_panel.rs +++ b/crates/git_ui/src/git_panel.rs @@ -4420,6 +4420,10 @@ impl Panel for GitPanel { "GitPanel" } + fn panel_key() -> &'static str { + GIT_PANEL_KEY + } + fn position(&self, _: &Window, cx: &App) -> DockPosition { GitPanelSettings::get_global(cx).dock } diff --git a/crates/outline_panel/src/outline_panel.rs b/crates/outline_panel/src/outline_panel.rs index 4a4990b40a5f3f7ad2f182e007593e62a8bcd015..ebc5946acf97b763d7ec06d264aeaa7169d7c68b 100644 --- a/crates/outline_panel/src/outline_panel.rs +++ b/crates/outline_panel/src/outline_panel.rs @@ -4838,6 +4838,10 @@ impl Panel for OutlinePanel { "Outline Panel" } + fn panel_key() -> &'static str { + OUTLINE_PANEL_KEY + } + fn position(&self, _: &Window, cx: &App) -> DockPosition { match OutlinePanelSettings::get_global(cx).dock { DockSide::Left => DockPosition::Left, diff --git a/crates/project_panel/src/project_panel.rs b/crates/project_panel/src/project_panel.rs index d9decd954b8f15abd3d5126b3e8f475013a9b895..98ff619588d42f80ec53e9e91133d47e63cfcbee 100644 --- a/crates/project_panel/src/project_panel.rs +++ b/crates/project_panel/src/project_panel.rs @@ -6016,6 +6016,10 @@ impl Panel for ProjectPanel { "Project Panel" } + fn panel_key() -> &'static str { + PROJECT_PANEL_KEY + } + fn starts_open(&self, _: &Window, cx: &App) -> bool { if !ProjectPanelSettings::get_global(cx).starts_open { return false; diff --git a/crates/terminal_view/src/terminal_panel.rs b/crates/terminal_view/src/terminal_panel.rs index 3f0ea0e274edce225d8fd4754043b49d76bf05b4..cb80d58c13128fad19b647e060001e5cf63f052b 100644 --- a/crates/terminal_view/src/terminal_panel.rs +++ b/crates/terminal_view/src/terminal_panel.rs @@ -1664,6 +1664,10 @@ impl Panel for TerminalPanel { "TerminalPanel" } + fn panel_key() -> &'static str { + TERMINAL_PANEL_KEY + } + fn icon(&self, _window: &Window, cx: &App) -> Option { if (self.is_enabled(cx) || !self.has_no_terminals(cx)) && TerminalSettings::get_global(cx).button diff --git a/crates/workspace/src/dock.rs b/crates/workspace/src/dock.rs index d67d3c81a9fbf67518a49c6c75a842a50ca78684..5958ba210f2dc984c3a8d698013a69548bbb3fcf 100644 --- a/crates/workspace/src/dock.rs +++ b/crates/workspace/src/dock.rs @@ -27,6 +27,7 @@ pub use proto::PanelId; pub trait Panel: Focusable + EventEmitter + Render + Sized { fn persistent_name() -> &'static str; + fn panel_key() -> &'static str; fn position(&self, window: &Window, cx: &App) -> DockPosition; fn position_is_valid(&self, position: DockPosition) -> bool; fn set_position(&mut self, position: DockPosition, window: &mut Window, cx: &mut Context); @@ -61,6 +62,7 @@ pub trait Panel: Focusable + EventEmitter + Render + Sized { pub trait PanelHandle: Send + Sync { fn panel_id(&self) -> EntityId; fn persistent_name(&self) -> &'static str; + fn panel_key(&self) -> &'static str; fn position(&self, window: &Window, cx: &App) -> DockPosition; fn position_is_valid(&self, position: DockPosition, cx: &App) -> bool; fn set_position(&self, position: DockPosition, window: &mut Window, cx: &mut App); @@ -108,6 +110,10 @@ where T::persistent_name() } + fn panel_key(&self) -> &'static str { + T::panel_key() + } + fn position(&self, window: &Window, cx: &App) -> DockPosition { self.read(cx).position(window, cx) } @@ -1016,6 +1022,10 @@ pub mod test { "TestPanel" } + fn panel_key() -> &'static str { + "TestPanel" + } + fn position(&self, _window: &Window, _: &App) -> super::DockPosition { self.position } diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index 85a17c244bebe5d3c33d1bda1fe4ae5758038e56..53f416ae805e692db48b6676a3484e6f839feb99 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -6373,6 +6373,24 @@ impl Render for Workspace { } } + if self.left_dock.read(cx).is_open() { + if let Some(active_panel) = self.left_dock.read(cx).active_panel() { + context.set("left_dock", active_panel.panel_key()); + } + } + + if self.right_dock.read(cx).is_open() { + if let Some(active_panel) = self.right_dock.read(cx).active_panel() { + context.set("right_dock", active_panel.panel_key()); + } + } + + if self.bottom_dock.read(cx).is_open() { + if let Some(active_panel) = self.bottom_dock.read(cx).active_panel() { + context.set("bottom_dock", active_panel.panel_key()); + } + } + let centered_layout = self.centered_layout && self.center.panes().len() == 1 && self.active_item(cx).is_some();