@@ -667,17 +667,22 @@ impl Application for App {
667667 // TODO assumes only one active workspace per output
668668 let workspaces = self . workspaces . for_output ( & output) . collect :: < Vec < _ > > ( ) ;
669669 if let Some ( workspace_idx) = workspaces. iter ( ) . position ( |i| i. is_active ( ) ) {
670- let workspace = match direction {
671- // Next workspace on output
672- ScrollDirection :: Next => workspaces[ workspace_idx + 1 ..] . iter ( ) . next ( ) ,
673- // Previous workspace on output
674- ScrollDirection :: Prev => workspaces[ ..workspace_idx] . iter ( ) . last ( ) ,
670+ let new_workspace_idx = match direction {
671+ // Next workspace on output, wrapping to start
672+ ScrollDirection :: Next => ( workspace_idx + 1 ) % workspaces. len ( ) ,
673+ // Previous workspace on output, wrapping to end
674+ ScrollDirection :: Prev => {
675+ if workspace_idx == 0 {
676+ workspaces. len ( ) - 1
677+ } else {
678+ workspace_idx - 1
679+ }
680+ }
675681 } ;
676- if let Some ( workspace) = workspace {
677- self . send_wayland_cmd ( backend:: Cmd :: ActivateWorkspace (
678- workspace. handle ( ) . clone ( ) ,
679- ) ) ;
680- }
682+ let workspace = workspaces[ new_workspace_idx] ;
683+ self . send_wayland_cmd ( backend:: Cmd :: ActivateWorkspace (
684+ workspace. handle ( ) . clone ( ) ,
685+ ) ) ;
681686 }
682687 }
683688 Msg :: DndWorkspaceDrag => { }
0 commit comments