@@ -120,6 +120,8 @@ private set
120120 OnPropertyChanged ( nameof ( HasUnresolvedConflicts ) ) ;
121121 OnPropertyChanged ( nameof ( StatusText ) ) ;
122122 OnPropertyChanged ( nameof ( CanSave ) ) ;
123+ OnPropertyChanged ( nameof ( HasPrevConflict ) ) ;
124+ OnPropertyChanged ( nameof ( HasNextConflict ) ) ;
123125 }
124126 }
125127 }
@@ -151,8 +153,8 @@ private set
151153 }
152154 }
153155
154- public bool HasPrevConflict => _currentConflictIndex > 0 ;
155- public bool HasNextConflict => _currentConflictIndex < _totalConflicts - 1 ;
156+ public bool HasPrevConflict => UnresolvedConflictCount > 0 ;
157+ public bool HasNextConflict => UnresolvedConflictCount > 0 ;
156158
157159 public int CurrentConflictLine
158160 {
@@ -813,19 +815,55 @@ public void UndoResolutionAtIndex(int conflictIndex)
813815
814816 public void GotoPrevConflict ( )
815817 {
816- if ( _currentConflictIndex > 0 )
818+ if ( UnresolvedConflictCount == 0 || _conflictRegions . Count == 0 )
819+ return ;
820+
821+ // Handle edge case where no conflict is currently selected
822+ int startIndex = _currentConflictIndex >= 0 ? _currentConflictIndex : 0 ;
823+
824+ // Search for the previous unresolved conflict with wrap-around
825+ int index = startIndex - 1 ;
826+ if ( index < 0 )
827+ index = _conflictRegions . Count - 1 ;
828+
829+ int iterations = 0 ;
830+ while ( iterations < _conflictRegions . Count )
817831 {
818- CurrentConflictIndex -- ;
819- UpdateCurrentConflictLine ( ) ;
832+ if ( ! _conflictRegions [ index ] . IsResolved )
833+ {
834+ CurrentConflictIndex = index ;
835+ UpdateCurrentConflictLine ( ) ;
836+ return ;
837+ }
838+ index -- ;
839+ if ( index < 0 )
840+ index = _conflictRegions . Count - 1 ;
841+ iterations ++ ;
820842 }
821843 }
822844
823845 public void GotoNextConflict ( )
824846 {
825- if ( _currentConflictIndex < _totalConflicts - 1 )
847+ if ( UnresolvedConflictCount == 0 || _conflictRegions . Count == 0 )
848+ return ;
849+
850+ // Handle edge case where no conflict is currently selected
851+ int startIndex = _currentConflictIndex >= 0 ? _currentConflictIndex : - 1 ;
852+
853+ // Search for the next unresolved conflict with wrap-around
854+ int index = ( startIndex + 1 ) % _conflictRegions . Count ;
855+
856+ int iterations = 0 ;
857+ while ( iterations < _conflictRegions . Count )
826858 {
827- CurrentConflictIndex ++ ;
828- UpdateCurrentConflictLine ( ) ;
859+ if ( ! _conflictRegions [ index ] . IsResolved )
860+ {
861+ CurrentConflictIndex = index ;
862+ UpdateCurrentConflictLine ( ) ;
863+ return ;
864+ }
865+ index = ( index + 1 ) % _conflictRegions . Count ;
866+ iterations ++ ;
829867 }
830868 }
831869
0 commit comments