Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
workspace: Add actions for cycling between windows (#23356)
tims938b7bb183c7
diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rsindex 20b4659c938..b54b7974491 100644--- a/crates/workspace/src/workspace.rs+++ b/crates/workspace/src/workspace.rs@@ -125,6 +125,8 @@ actions!([ActivateNextPane,ActivatePreviousPane,+ ActivateNextWindow,+ ActivatePreviousWindow,AddFolderToProject,ClearAllNotifications,CloseAllDocks,@@ -4542,6 +4544,12 @@ impl Workspace {.on_action(cx.listener(|workspace, _: &ActivateNextPane, cx| workspace.activate_next_pane(cx)),)+ .on_action(cx.listener(|workspace, _: &ActivateNextWindow, cx| {+ workspace.activate_next_window(cx)+ }))+ .on_action(cx.listener(|workspace, _: &ActivatePreviousWindow, cx| {+ workspace.activate_previous_window(cx)+ })).on_action(cx.listener(|workspace, action: &ActivatePaneInDirection, cx| {workspace.activate_pane_in_direction(action.0, cx)@@ -4700,6 +4708,39 @@ impl Workspace {pub fn zoomed_item(&self) -> Option<&AnyWeakView> {self.zoomed.as_ref()}++ pub fn activate_next_window(&mut self, cx: &mut ViewContext<Self>) {+ let Some(current_window_id) = cx.active_window().map(|a| a.window_id()) else {+ return;+ };+ let windows = cx.windows();+ let Some(next_window) = windows+ .iter()+ .cycle()+ .skip_while(|window| window.window_id() != current_window_id)+ .nth(1)+ else {+ return;+ };+ next_window.update(cx, |_, cx| cx.activate_window()).ok();+ }++ pub fn activate_previous_window(&mut self, cx: &mut ViewContext<Self>) {+ let Some(current_window_id) = cx.active_window().map(|a| a.window_id()) else {+ return;+ };+ let windows = cx.windows();+ let Some(prev_window) = windows+ .iter()+ .rev()+ .cycle()+ .skip_while(|window| window.window_id() != current_window_id)+ .nth(1)+ else {+ return;+ };+ prev_window.update(cx, |_, cx| cx.activate_window()).ok();+ }}fn leader_border_for_pane(