Skip to content

Commit 5d37419

Browse files
ConradIrwinBrandan
andauthored
Add terminal::Toggle (#37585)
Co-Authored-By: Brandan <b5@n0.computer> Release Notes: - Added a new action `terminal::Toggle` that is by default bound to 'ctrl-\`'. This copies the default behaviour from VSCode and Jetbrains where the terminal opens and closes correctly. If you'd like the old behaviour you can rebind 'ctrl-\`' to `terminal::ToggleFocus` Co-authored-by: Brandan <b5@n0.computer>
1 parent b65fb06 commit 5d37419

File tree

8 files changed

+26
-7
lines changed

8 files changed

+26
-7
lines changed

assets/keymaps/default-linux.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@
583583
"ctrl-n": "workspace::NewFile",
584584
"shift-new": "workspace::NewWindow",
585585
"ctrl-shift-n": "workspace::NewWindow",
586-
"ctrl-`": "terminal_panel::ToggleFocus",
586+
"ctrl-`": "terminal_panel::Toggle",
587587
"f10": ["app_menu::OpenApplicationMenu", "Zed"],
588588
"alt-1": ["workspace::ActivatePane", 0],
589589
"alt-2": ["workspace::ActivatePane", 1],

assets/keymaps/default-macos.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@
649649
"alt-shift-enter": "toast::RunAction",
650650
"cmd-shift-s": "workspace::SaveAs",
651651
"cmd-shift-n": "workspace::NewWindow",
652-
"ctrl-`": "terminal_panel::ToggleFocus",
652+
"ctrl-`": "terminal_panel::Toggle",
653653
"cmd-1": ["workspace::ActivatePane", 0],
654654
"cmd-2": ["workspace::ActivatePane", 1],
655655
"cmd-3": ["workspace::ActivatePane", 2],

assets/keymaps/default-windows.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@
599599
"ctrl-n": "workspace::NewFile",
600600
"shift-new": "workspace::NewWindow",
601601
"ctrl-shift-n": "workspace::NewWindow",
602-
"ctrl-`": "terminal_panel::ToggleFocus",
602+
"ctrl-`": "terminal_panel::Toggle",
603603
"f10": ["app_menu::OpenApplicationMenu", "Zed"],
604604
"alt-1": ["workspace::ActivatePane", 0],
605605
"alt-2": ["workspace::ActivatePane", 1],

assets/keymaps/linux/jetbrains.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125
{
126126
"context": "Workspace || Editor",
127127
"bindings": {
128-
"alt-f12": "terminal_panel::ToggleFocus",
128+
"alt-f12": "terminal_panel::Toggle",
129129
"ctrl-shift-k": "git::Push"
130130
}
131131
},

assets/keymaps/macos/jetbrains.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@
127127
{
128128
"context": "Workspace || Editor",
129129
"bindings": {
130-
"alt-f12": "terminal_panel::ToggleFocus",
130+
"alt-f12": "terminal_panel::Toggle",
131131
"cmd-shift-k": "git::Push"
132132
}
133133
},

crates/terminal_view/src/terminal_panel.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ const TERMINAL_PANEL_KEY: &str = "TerminalPanel";
4949
actions!(
5050
terminal_panel,
5151
[
52+
/// Toggles the terminal panel.
53+
Toggle,
5254
/// Toggles focus on the terminal panel.
5355
ToggleFocus
5456
]
@@ -64,6 +66,13 @@ pub fn init(cx: &mut App) {
6466
workspace.toggle_panel_focus::<TerminalPanel>(window, cx);
6567
}
6668
});
69+
workspace.register_action(|workspace, _: &Toggle, window, cx| {
70+
if is_enabled_in_workspace(workspace, cx) {
71+
if !workspace.toggle_panel_focus::<TerminalPanel>(window, cx) {
72+
workspace.close_panel::<TerminalPanel>(window, cx);
73+
}
74+
}
75+
});
6776
},
6877
)
6978
.detach();

crates/vim/src/command.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,8 +1265,8 @@ fn generate_commands(_: &App) -> Vec<VimCommand> {
12651265
VimCommand::str(("L", "explore"), "project_panel::ToggleFocus"),
12661266
VimCommand::str(("S", "explore"), "project_panel::ToggleFocus"),
12671267
VimCommand::str(("Ve", "xplore"), "project_panel::ToggleFocus"),
1268-
VimCommand::str(("te", "rm"), "terminal_panel::ToggleFocus"),
1269-
VimCommand::str(("T", "erm"), "terminal_panel::ToggleFocus"),
1268+
VimCommand::str(("te", "rm"), "terminal_panel::Toggle"),
1269+
VimCommand::str(("T", "erm"), "terminal_panel::Toggle"),
12701270
VimCommand::str(("C", "ollab"), "collab_panel::ToggleFocus"),
12711271
VimCommand::str(("Ch", "at"), "chat_panel::ToggleFocus"),
12721272
VimCommand::str(("No", "tifications"), "notification_panel::ToggleFocus"),

crates/workspace/src/workspace.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3093,6 +3093,16 @@ impl Workspace {
30933093
}
30943094
}
30953095

3096+
pub fn close_panel<T: Panel>(&self, window: &mut Window, cx: &mut Context<Self>) {
3097+
for dock in self.all_docks().iter() {
3098+
dock.update(cx, |dock, cx| {
3099+
if dock.panel::<T>().is_some() {
3100+
dock.set_open(false, window, cx)
3101+
}
3102+
})
3103+
}
3104+
}
3105+
30963106
pub fn panel<T: Panel>(&self, cx: &App) -> Option<Entity<T>> {
30973107
self.all_docks()
30983108
.iter()

0 commit comments

Comments
 (0)