@@ -679,17 +679,22 @@ impl Application for App {
679679 // TODO assumes only one active workspace per output
680680 let workspaces = self . workspaces . for_output ( & output) . collect :: < Vec < _ > > ( ) ;
681681 if let Some ( workspace_idx) = workspaces. iter ( ) . position ( |i| i. is_active ( ) ) {
682- let workspace = match direction {
683- // Next workspace on output
684- ScrollDirection :: Next => workspaces[ workspace_idx + 1 ..] . iter ( ) . next ( ) ,
685- // Previous workspace on output
686- ScrollDirection :: Prev => workspaces[ ..workspace_idx] . iter ( ) . last ( ) ,
682+ let new_workspace_idx = match direction {
683+ // Next workspace on output, wrapping to start
684+ ScrollDirection :: Next => ( workspace_idx + 1 ) % workspaces. len ( ) ,
685+ // Previous workspace on output, wrapping to end
686+ ScrollDirection :: Prev => {
687+ if workspace_idx == 0 {
688+ workspaces. len ( ) - 1
689+ } else {
690+ workspace_idx - 1
691+ }
692+ }
687693 } ;
688- if let Some ( workspace) = workspace {
689- self . send_wayland_cmd ( backend:: Cmd :: ActivateWorkspace (
690- workspace. handle ( ) . clone ( ) ,
691- ) ) ;
692- }
694+ let workspace = workspaces[ new_workspace_idx] ;
695+ self . send_wayland_cmd ( backend:: Cmd :: ActivateWorkspace (
696+ workspace. handle ( ) . clone ( ) ,
697+ ) ) ;
693698 }
694699 }
695700 Msg :: DndWorkspaceDrag => { }
0 commit comments