diff --git a/crates/workspace/src/multi_workspace.rs b/crates/workspace/src/multi_workspace.rs index 2644ad4c620a57866a910f091954e24c8e4eedb8..c3ec2e1c61e1b038f91a57dddac0b7a7b89b337e 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) { + 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.cycle_workspace(1, window, cx); + } + + fn previous_workspace( + &mut self, + _: &PreviousWorkspace, + window: &mut Window, + cx: &mut Context, + ) { + 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.rs index bd79918eb435dd05b5e4be4459a0e2e6972182ab..0acc15697008d427efbe0371040a88945b8694c1 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};