@@ -487,43 +487,21 @@ public virtual void UpdateSelectedChunk(double y)
487487 {
488488 }
489489
490- public virtual void GotoFirstChange ( )
490+ public void GotoChange ( ViewModels . BlockNavigationDirection direction )
491491 {
492- var first = BlockNavigation . GotoFirst ( ) ;
493- if ( first != null )
494- {
495- TextArea . Caret . Line = first . Start ;
496- ScrollToLine ( first . Start ) ;
497- }
498- }
492+ if ( DataContext is not ViewModels . TextDiffContext ctx )
493+ return ;
499494
500- public virtual void GotoPrevChange ( )
501- {
502- var prev = BlockNavigation . GotoPrev ( ) ;
503- if ( prev != null )
495+ var block = BlockNavigation . Goto ( direction ) ;
496+ if ( block != null )
504497 {
505- TextArea . Caret . Line = prev . Start ;
506- ScrollToLine ( prev . Start ) ;
507- }
508- }
498+ TextArea . Caret . Line = block . Start ;
499+ ScrollToLine ( block . Start ) ;
509500
510- public virtual void GotoNextChange ( )
511- {
512- var next = BlockNavigation . GotoNext ( ) ;
513- if ( next != null )
514- {
515- TextArea . Caret . Line = next . Start ;
516- ScrollToLine ( next . Start ) ;
517- }
518- }
501+ if ( ctx . IsSideBySide ( ) )
502+ {
519503
520- public virtual void GotoLastChange ( )
521- {
522- var next = BlockNavigation . GotoLast ( ) ;
523- if ( next != null )
524- {
525- TextArea . Caret . Line = next . Start ;
526- ScrollToLine ( next . Start ) ;
504+ }
527505 }
528506 }
529507
@@ -618,9 +596,9 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
618596 }
619597 }
620598
621- protected override void OnDataContextBeginUpdate ( )
599+ protected override void OnDataContextChanged ( EventArgs e )
622600 {
623- base . OnDataContextBeginUpdate ( ) ;
601+ base . OnDataContextChanged ( e ) ;
624602 AutoScrollToFirstChange ( ) ;
625603 }
626604
@@ -805,9 +783,6 @@ private void AutoScrollToFirstChange()
805783 if ( DataContext is not ViewModels . TextDiffContext ctx )
806784 return ;
807785
808- if ( ctx . IsSideBySide ( ) && ! IsOld )
809- return ;
810-
811786 var curBlock = ctx . BlockNavigation . GetCurrentBlock ( ) ;
812787 if ( curBlock == null )
813788 return ;
@@ -819,8 +794,9 @@ private void AutoScrollToFirstChange()
819794 var scroller = this . FindDescendantOfType < ScrollViewer > ( ) ;
820795 if ( scroller != null )
821796 {
822- ctx . ScrollOffset = new Vector ( 0 , vOffset ) ;
823- scroller . Offset = ctx . ScrollOffset ;
797+ var scrollOffset = new Vector ( 0 , vOffset ) ;
798+ scroller . Offset = scrollOffset ;
799+ ctx . ScrollOffset = scrollOffset ;
824800 }
825801 }
826802 }
@@ -1098,30 +1074,6 @@ public class SingleSideTextDiffPresenter : ThemedTextDiffPresenter
10981074 return [ ] ;
10991075 }
11001076
1101- public override void GotoFirstChange ( )
1102- {
1103- base . GotoFirstChange ( ) ;
1104- SyncScrollOffset ( ) ;
1105- }
1106-
1107- public override void GotoPrevChange ( )
1108- {
1109- base . GotoPrevChange ( ) ;
1110- SyncScrollOffset ( ) ;
1111- }
1112-
1113- public override void GotoNextChange ( )
1114- {
1115- base . GotoNextChange ( ) ;
1116- SyncScrollOffset ( ) ;
1117- }
1118-
1119- public override void GotoLastChange ( )
1120- {
1121- base . GotoLastChange ( ) ;
1122- SyncScrollOffset ( ) ;
1123- }
1124-
11251077 public override void UpdateSelectedChunk ( double y )
11261078 {
11271079 if ( DataContext is not ViewModels . TwoSideTextDiff diff )
@@ -1318,12 +1270,6 @@ private void OnBlockNavigationPropertyChanged(object sender, PropertyChangedEven
13181270 TextArea ? . TextView ? . Redraw ( ) ;
13191271 }
13201272
1321- private void SyncScrollOffset ( )
1322- {
1323- if ( _scrollViewer is not null && DataContext is ViewModels . TwoSideTextDiff diff )
1324- diff . ScrollOffset = _scrollViewer . Offset ;
1325- }
1326-
13271273 private ScrollViewer _scrollViewer = null ;
13281274 }
13291275
0 commit comments