Rebind ctrl-` to toggle terminal panel focus

Also, add `ctrl-~` to create new terminals.

Co-Authored-By: Mikayla Maki <mikayla@zed.dev>
This commit is contained in:
Antonio Scandurra 2023-05-17 17:35:10 +02:00
parent 747fbfadeb
commit f097444546
5 changed files with 42 additions and 34 deletions

View file

@ -176,6 +176,12 @@ impl Dock {
.map_or(false, |panel| panel.has_focus(cx))
}
pub fn panel_index<T: Panel>(&self) -> Option<usize> {
self.panel_entries
.iter()
.position(|entry| entry.panel.as_any().is::<T>())
}
pub fn active_panel_index(&self) -> usize {
self.active_panel_index
}

View file

@ -116,6 +116,7 @@ actions!(
FollowNextCollaborator,
ToggleLeftDock,
NewTerminal,
ToggleTerminalFocus,
NewSearch,
Feedback,
Restart,
@ -1475,33 +1476,27 @@ impl Workspace {
cx.notify();
}
pub fn toggle_panel_focus(
&mut self,
dock_position: DockPosition,
panel_index: usize,
cx: &mut ViewContext<Self>,
) {
let dock = match dock_position {
DockPosition::Left => &mut self.left_dock,
DockPosition::Bottom => &mut self.bottom_dock,
DockPosition::Right => &mut self.right_dock,
};
let active_item = dock.update(cx, |dock, cx| {
dock.set_open(true, cx);
dock.activate_panel(panel_index, cx);
dock.active_panel().cloned()
});
if let Some(active_item) = active_item {
if active_item.has_focus(cx) {
cx.focus_self();
} else {
cx.focus(active_item.as_any());
pub fn toggle_panel_focus<T: Panel>(&mut self, cx: &mut ViewContext<Self>) {
for dock in [&self.left_dock, &self.bottom_dock, &self.right_dock] {
if let Some(panel_index) = dock.read(cx).panel_index::<T>() {
let active_item = dock.update(cx, |dock, cx| {
dock.set_open(true, cx);
dock.activate_panel(panel_index, cx);
dock.active_panel().cloned()
});
if let Some(active_item) = active_item {
if active_item.has_focus(cx) {
cx.focus_self();
} else {
cx.focus(active_item.as_any());
}
}
self.serialize_workspace(cx);
cx.notify();
break;
}
}
self.serialize_workspace(cx);
cx.notify();
}
fn zoom_out(&mut self, cx: &mut ViewContext<Self>) {