Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
multi_workspace: Add actions to cycle workspace (#52156)
Cameron Mcloughlinfb1a98cfeffd
diff --git a/crates/workspace/src/multi_workspace.rs b/crates/workspace/src/multi_workspace.rsindex 2644ad4c620..c3ec2e1c61e 100644--- a/crates/workspace/src/multi_workspace.rs+++ b/crates/workspace/src/multi_workspace.rs@@ -30,6 +30,10 @@ actions!(CloseWorkspaceSidebar,/// Moves focus to or from the workspace sidebar without closing it.FocusWorkspaceSidebar,+ /// Switches to the next workspace.+ NextWorkspace,+ /// Switches to the previous workspace.+ PreviousWorkspace,]);@@ -405,6 +409,29 @@ impl MultiWorkspace {cx.notify();}+ fn cycle_workspace(&mut self, delta: isize, window: &mut Window, cx: &mut Context<Self>) {+ let count = self.workspaces.len() as isize;+ if count <= 1 {+ return;+ }+ let current = self.active_workspace_index as isize;+ let next = ((current + delta).rem_euclid(count)) as usize;+ self.activate_index(next, window, cx);+ }++ fn next_workspace(&mut self, _: &NextWorkspace, window: &mut Window, cx: &mut Context<Self>) {+ self.cycle_workspace(1, window, cx);+ }++ fn previous_workspace(+ &mut self,+ _: &PreviousWorkspace,+ window: &mut Window,+ cx: &mut Context<Self>,+ ) {+ self.cycle_workspace(-1, window, cx);+ }+fn serialize(&mut self, cx: &mut App) {let window_id = self.window_id;let state = crate::persistence::model::MultiWorkspaceState {@@ -760,6 +787,8 @@ impl Render for MultiWorkspace {this.focus_sidebar(window, cx);},))+ .on_action(cx.listener(Self::next_workspace))+ .on_action(cx.listener(Self::previous_workspace))}).when(self.sidebar_open() && self.multi_workspace_enabled(cx),diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rsindex bd79918eb43..0acc1569700 100644--- a/crates/workspace/src/workspace.rs+++ b/crates/workspace/src/workspace.rs@@ -28,7 +28,8 @@ pub use crate::notifications::NotificationFrame;pub use dock::Panel;pub use multi_workspace::{CloseWorkspaceSidebar, DraggedSidebar, FocusWorkspaceSidebar, MultiWorkspace,- MultiWorkspaceEvent, Sidebar, SidebarHandle, ToggleWorkspaceSidebar,+ MultiWorkspaceEvent, NextWorkspace, PreviousWorkspace, Sidebar, SidebarHandle,+ ToggleWorkspaceSidebar,};pub use path_list::{PathList, SerializedPathList};pub use toast_layer::{ToastAction, ToastLayer, ToastView};