Skip to content

Commit 057c3c1

Browse files
authored
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: <img width="2032" height="1167" alt="Screenshot 2025-10-16 at 23 20 34" src="https://github.com/user-attachments/assets/116d0575-a1ae-4577-95b9-8415cda57e52" /> <img width="2032" height="1167" alt="Screenshot 2025-10-16 at 23 20 57" src="https://github.com/user-attachments/assets/000fdbb6-80bd-46e9-b668-f4b54ab708d2" /> <img width="2032" height="1167" alt="Screenshot 2025-10-16 at 23 21 37" src="https://github.com/user-attachments/assets/7b1c82da-b82f-4e14-a97c-3cd0e71bbca0" /> <img width="2032" height="1167" alt="Screenshot 2025-10-16 at 23 21 52" src="https://github.com/user-attachments/assets/1fd4b65a-09f7-47a9-a9b7-fdce4252aec3" /> <img width="2032" height="1167" alt="Screenshot 2025-10-16 at 23 22 38" src="https://github.com/user-attachments/assets/f4c2ac5c-e6f9-4e0e-b683-522b237e3328" /> 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
1 parent 13fe993 commit 057c3c1

File tree

10 files changed

+62
-0
lines changed

10 files changed

+62
-0
lines changed

crates/agent_ui/src/agent_panel.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,6 +1395,10 @@ impl Panel for AgentPanel {
13951395
"AgentPanel"
13961396
}
13971397

1398+
fn panel_key() -> &'static str {
1399+
AGENT_PANEL_KEY
1400+
}
1401+
13981402
fn position(&self, _window: &Window, cx: &App) -> DockPosition {
13991403
agent_panel_dock_position(cx)
14001404
}

crates/collab_ui/src/collab_panel.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3037,6 +3037,10 @@ impl Panel for CollabPanel {
30373037
"CollabPanel"
30383038
}
30393039

3040+
fn panel_key() -> &'static str {
3041+
COLLABORATION_PANEL_KEY
3042+
}
3043+
30403044
fn activation_priority(&self) -> u32 {
30413045
6
30423046
}

crates/collab_ui/src/notification_panel.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,10 @@ impl Panel for NotificationPanel {
612612
"NotificationPanel"
613613
}
614614

615+
fn panel_key() -> &'static str {
616+
NOTIFICATION_PANEL_KEY
617+
}
618+
615619
fn position(&self, _: &Window, cx: &App) -> DockPosition {
616620
NotificationPanelSettings::get_global(cx).dock
617621
}

crates/debugger_ui/src/debugger_panel.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ use workspace::{
4343
};
4444
use zed_actions::ToggleFocus;
4545

46+
const DEBUG_PANEL_KEY: &str = "DebugPanel";
47+
4648
pub struct DebugPanel {
4749
size: Pixels,
4850
active_session: Option<Entity<DebugSession>>,
@@ -1414,6 +1416,10 @@ impl Panel for DebugPanel {
14141416
"DebugPanel"
14151417
}
14161418

1419+
fn panel_key() -> &'static str {
1420+
DEBUG_PANEL_KEY
1421+
}
1422+
14171423
fn position(&self, _window: &Window, cx: &App) -> DockPosition {
14181424
DebuggerSettings::get_global(cx).dock.into()
14191425
}

crates/git_ui/src/git_panel.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4420,6 +4420,10 @@ impl Panel for GitPanel {
44204420
"GitPanel"
44214421
}
44224422

4423+
fn panel_key() -> &'static str {
4424+
GIT_PANEL_KEY
4425+
}
4426+
44234427
fn position(&self, _: &Window, cx: &App) -> DockPosition {
44244428
GitPanelSettings::get_global(cx).dock
44254429
}

crates/outline_panel/src/outline_panel.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4838,6 +4838,10 @@ impl Panel for OutlinePanel {
48384838
"Outline Panel"
48394839
}
48404840

4841+
fn panel_key() -> &'static str {
4842+
OUTLINE_PANEL_KEY
4843+
}
4844+
48414845
fn position(&self, _: &Window, cx: &App) -> DockPosition {
48424846
match OutlinePanelSettings::get_global(cx).dock {
48434847
DockSide::Left => DockPosition::Left,

crates/project_panel/src/project_panel.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6016,6 +6016,10 @@ impl Panel for ProjectPanel {
60166016
"Project Panel"
60176017
}
60186018

6019+
fn panel_key() -> &'static str {
6020+
PROJECT_PANEL_KEY
6021+
}
6022+
60196023
fn starts_open(&self, _: &Window, cx: &App) -> bool {
60206024
if !ProjectPanelSettings::get_global(cx).starts_open {
60216025
return false;

crates/terminal_view/src/terminal_panel.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,6 +1664,10 @@ impl Panel for TerminalPanel {
16641664
"TerminalPanel"
16651665
}
16661666

1667+
fn panel_key() -> &'static str {
1668+
TERMINAL_PANEL_KEY
1669+
}
1670+
16671671
fn icon(&self, _window: &Window, cx: &App) -> Option<IconName> {
16681672
if (self.is_enabled(cx) || !self.has_no_terminals(cx))
16691673
&& TerminalSettings::get_global(cx).button

crates/workspace/src/dock.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub use proto::PanelId;
2727

2828
pub trait Panel: Focusable + EventEmitter<PanelEvent> + Render + Sized {
2929
fn persistent_name() -> &'static str;
30+
fn panel_key() -> &'static str;
3031
fn position(&self, window: &Window, cx: &App) -> DockPosition;
3132
fn position_is_valid(&self, position: DockPosition) -> bool;
3233
fn set_position(&mut self, position: DockPosition, window: &mut Window, cx: &mut Context<Self>);
@@ -61,6 +62,7 @@ pub trait Panel: Focusable + EventEmitter<PanelEvent> + Render + Sized {
6162
pub trait PanelHandle: Send + Sync {
6263
fn panel_id(&self) -> EntityId;
6364
fn persistent_name(&self) -> &'static str;
65+
fn panel_key(&self) -> &'static str;
6466
fn position(&self, window: &Window, cx: &App) -> DockPosition;
6567
fn position_is_valid(&self, position: DockPosition, cx: &App) -> bool;
6668
fn set_position(&self, position: DockPosition, window: &mut Window, cx: &mut App);
@@ -108,6 +110,10 @@ where
108110
T::persistent_name()
109111
}
110112

113+
fn panel_key(&self) -> &'static str {
114+
T::panel_key()
115+
}
116+
111117
fn position(&self, window: &Window, cx: &App) -> DockPosition {
112118
self.read(cx).position(window, cx)
113119
}
@@ -1016,6 +1022,10 @@ pub mod test {
10161022
"TestPanel"
10171023
}
10181024

1025+
fn panel_key() -> &'static str {
1026+
"TestPanel"
1027+
}
1028+
10191029
fn position(&self, _window: &Window, _: &App) -> super::DockPosition {
10201030
self.position
10211031
}

crates/workspace/src/workspace.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6373,6 +6373,24 @@ impl Render for Workspace {
63736373
}
63746374
}
63756375

6376+
if self.left_dock.read(cx).is_open() {
6377+
if let Some(active_panel) = self.left_dock.read(cx).active_panel() {
6378+
context.set("left_dock", active_panel.panel_key());
6379+
}
6380+
}
6381+
6382+
if self.right_dock.read(cx).is_open() {
6383+
if let Some(active_panel) = self.right_dock.read(cx).active_panel() {
6384+
context.set("right_dock", active_panel.panel_key());
6385+
}
6386+
}
6387+
6388+
if self.bottom_dock.read(cx).is_open() {
6389+
if let Some(active_panel) = self.bottom_dock.read(cx).active_panel() {
6390+
context.set("bottom_dock", active_panel.panel_key());
6391+
}
6392+
}
6393+
63766394
let centered_layout = self.centered_layout
63776395
&& self.center.panes().len() == 1
63786396
&& self.active_item(cx).is_some();

0 commit comments

Comments
 (0)