@@ -553,7 +553,7 @@ public virtual void UpdateSelectedChunk(double y)
553
553
{
554
554
}
555
555
556
- public void GotoFirstChange ( )
556
+ public virtual void GotoFirstChange ( )
557
557
{
558
558
var blockNavigation = BlockNavigation ;
559
559
if ( blockNavigation != null )
@@ -567,7 +567,7 @@ public void GotoFirstChange()
567
567
}
568
568
}
569
569
570
- public void GotoPrevChange ( )
570
+ public virtual void GotoPrevChange ( )
571
571
{
572
572
var blockNavigation = BlockNavigation ;
573
573
if ( blockNavigation != null )
@@ -623,7 +623,7 @@ public void GotoPrevChange()
623
623
}
624
624
}
625
625
626
- public void GotoNextChange ( )
626
+ public virtual void GotoNextChange ( )
627
627
{
628
628
var blockNavigation = BlockNavigation ;
629
629
if ( blockNavigation != null )
@@ -665,7 +665,7 @@ public void GotoNextChange()
665
665
}
666
666
}
667
667
668
- public void GotoLastChange ( )
668
+ public virtual void GotoLastChange ( )
669
669
{
670
670
var blockNavigation = BlockNavigation ;
671
671
if ( blockNavigation != null )
@@ -766,15 +766,13 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
766
766
{
767
767
var oldValue = change . OldValue as ViewModels . BlockNavigation ;
768
768
if ( oldValue != null )
769
- {
770
769
oldValue . PropertyChanged -= OnBlockNavigationPropertyChanged ;
771
- if ( oldValue . Current != - 1 )
772
- TextArea ? . TextView ? . Redraw ( ) ;
773
- }
774
770
775
771
var newValue = change . NewValue as ViewModels . BlockNavigation ;
776
772
if ( newValue != null )
777
773
newValue . PropertyChanged += OnBlockNavigationPropertyChanged ;
774
+
775
+ TextArea ? . TextView ? . Redraw ( ) ;
778
776
}
779
777
}
780
778
@@ -793,9 +791,10 @@ private void OnTextAreaKeyDown(object sender, KeyEventArgs e)
793
791
base . OnKeyDown ( e ) ;
794
792
}
795
793
796
- private void OnBlockNavigationPropertyChanged ( object _1 , PropertyChangedEventArgs _2 )
794
+ private void OnBlockNavigationPropertyChanged ( object _1 , PropertyChangedEventArgs e )
797
795
{
798
- TextArea ? . TextView ? . Redraw ( ) ;
796
+ if ( e . PropertyName == "Current" )
797
+ TextArea ? . TextView ? . Redraw ( ) ;
799
798
}
800
799
801
800
private void OnTextViewContextRequested ( object sender , ContextRequestedEventArgs e )
@@ -1223,19 +1222,18 @@ protected override void OnLoaded(RoutedEventArgs e)
1223
1222
{
1224
1223
base . OnLoaded ( e ) ;
1225
1224
1226
- var scroller = this . FindDescendantOfType < ScrollViewer > ( ) ;
1227
- if ( scroller != null )
1225
+ _scrollViewer = this . FindDescendantOfType < ScrollViewer > ( ) ;
1226
+ if ( _scrollViewer != null )
1228
1227
{
1229
- scroller . Bind ( ScrollViewer . OffsetProperty , new Binding ( "ScrollOffset" , BindingMode . TwoWay ) ) ;
1230
- scroller . ScrollChanged += OnTextViewScrollChanged ;
1228
+ _scrollViewer . Bind ( ScrollViewer . OffsetProperty , new Binding ( "ScrollOffset" , BindingMode . TwoWay ) ) ;
1229
+ _scrollViewer . ScrollChanged += OnTextViewScrollChanged ;
1231
1230
}
1232
1231
}
1233
1232
1234
1233
protected override void OnUnloaded ( RoutedEventArgs e )
1235
1234
{
1236
- var scroller = this . FindDescendantOfType < ScrollViewer > ( ) ;
1237
- if ( scroller != null )
1238
- scroller . ScrollChanged -= OnTextViewScrollChanged ;
1235
+ if ( _scrollViewer != null )
1236
+ _scrollViewer . ScrollChanged -= OnTextViewScrollChanged ;
1239
1237
1240
1238
base . OnUnloaded ( e ) ;
1241
1239
}
@@ -1274,9 +1272,11 @@ protected override void OnDataContextChanged(EventArgs e)
1274
1272
1275
1273
private void OnTextViewScrollChanged ( object sender , ScrollChangedEventArgs e )
1276
1274
{
1277
- if ( sender is ScrollViewer { IsExpanded : true , IsPointerOver : true } scroller )
1275
+ if ( _scrollViewer is { IsExpanded : true , IsPointerOver : true } )
1278
1276
TrySetChunk ( null ) ;
1279
1277
}
1278
+
1279
+ private ScrollViewer _scrollViewer = null ;
1280
1280
}
1281
1281
1282
1282
public class SingleSideTextDiffPresenter : ThemedTextDiffPresenter
@@ -1288,14 +1288,6 @@ public class SingleSideTextDiffPresenter : ThemedTextDiffPresenter
1288
1288
TextArea . LeftMargins . Add ( new LineModifyTypeMargin ( ) ) ;
1289
1289
}
1290
1290
1291
- public void ForceSyncScrollOffset ( )
1292
- {
1293
- if ( _scrollViewer == null )
1294
- return ;
1295
- if ( DataContext is ViewModels . TwoSideTextDiff diff )
1296
- diff . SyncScrollOffset = _scrollViewer ? . Offset ?? Vector . Zero ;
1297
- }
1298
-
1299
1291
public override List < Models . TextDiffLine > GetLines ( )
1300
1292
{
1301
1293
if ( DataContext is ViewModels . TwoSideTextDiff diff )
@@ -1310,6 +1302,30 @@ public override int GetMaxLineNumber()
1310
1302
return 0 ;
1311
1303
}
1312
1304
1305
+ public override void GotoFirstChange ( )
1306
+ {
1307
+ base . GotoFirstChange ( ) ;
1308
+ DirectSyncScrollOffset ( ) ;
1309
+ }
1310
+
1311
+ public override void GotoPrevChange ( )
1312
+ {
1313
+ base . GotoPrevChange ( ) ;
1314
+ DirectSyncScrollOffset ( ) ;
1315
+ }
1316
+
1317
+ public override void GotoNextChange ( )
1318
+ {
1319
+ base . GotoNextChange ( ) ;
1320
+ DirectSyncScrollOffset ( ) ;
1321
+ }
1322
+
1323
+ public override void GotoLastChange ( )
1324
+ {
1325
+ base . GotoLastChange ( ) ;
1326
+ DirectSyncScrollOffset ( ) ;
1327
+ }
1328
+
1313
1329
public override void UpdateSelectedChunk ( double y )
1314
1330
{
1315
1331
var diff = DataContext as ViewModels . TwoSideTextDiff ;
@@ -1497,11 +1513,17 @@ private void OnTextViewScrollChanged(object sender, ScrollChangedEventArgs e)
1497
1513
{
1498
1514
diff . SyncScrollOffset = _scrollViewer ? . Offset ?? Vector . Zero ;
1499
1515
1500
- if ( sender is ScrollViewer { IsExpanded : true , IsPointerOver : true } scroller )
1516
+ if ( _scrollViewer is { IsExpanded : true , IsPointerOver : true } )
1501
1517
TrySetChunk ( null ) ;
1502
1518
}
1503
1519
}
1504
1520
1521
+ private void DirectSyncScrollOffset ( )
1522
+ {
1523
+ if ( _scrollViewer is { } && DataContext is ViewModels . TwoSideTextDiff diff )
1524
+ diff . SyncScrollOffset = _scrollViewer ? . Offset ?? Vector . Zero ;
1525
+ }
1526
+
1505
1527
private ScrollViewer _scrollViewer = null ;
1506
1528
}
1507
1529
@@ -1679,13 +1701,13 @@ public ViewModels.BlockNavigation BlockNavigation
1679
1701
set => SetValue ( BlockNavigationProperty , value ) ;
1680
1702
}
1681
1703
1682
- public static readonly StyledProperty < string > BlockNavigationIndicatorProperty =
1683
- AvaloniaProperty . Register < TextDiffView , string > ( nameof ( BlockNavigationIndicator ) ) ;
1704
+ public static readonly RoutedEvent < RoutedEventArgs > BlockNavigationChangedEvent =
1705
+ RoutedEvent . Register < TextDiffView , RoutedEventArgs > ( nameof ( BlockNavigationChanged ) , RoutingStrategies . Tunnel | RoutingStrategies . Bubble ) ;
1684
1706
1685
- public string BlockNavigationIndicator
1707
+ public event EventHandler < RoutedEventArgs > BlockNavigationChanged
1686
1708
{
1687
- get => GetValue ( BlockNavigationIndicatorProperty ) ;
1688
- set => SetValue ( BlockNavigationIndicatorProperty , value ) ;
1709
+ add { AddHandler ( BlockNavigationChangedEvent , value ) ; }
1710
+ remove { RemoveHandler ( BlockNavigationChangedEvent , value ) ; }
1689
1711
}
1690
1712
1691
1713
static TextDiffView ( )
@@ -1723,54 +1745,26 @@ public TextDiffView()
1723
1745
1724
1746
public void GotoFirstChange ( )
1725
1747
{
1726
- var presenter = this . FindDescendantOfType < ThemedTextDiffPresenter > ( ) ;
1727
- if ( presenter == null )
1728
- return ;
1729
-
1730
- presenter . GotoFirstChange ( ) ;
1731
- if ( presenter is SingleSideTextDiffPresenter singleSide )
1732
- singleSide . ForceSyncScrollOffset ( ) ;
1733
-
1734
- BlockNavigationIndicator = BlockNavigation ? . Indicator ?? string . Empty ;
1748
+ this . FindDescendantOfType < ThemedTextDiffPresenter > ( ) ? . GotoFirstChange ( ) ;
1749
+ RaiseEvent ( new RoutedEventArgs ( BlockNavigationChangedEvent ) ) ;
1735
1750
}
1736
1751
1737
1752
public void GotoPrevChange ( )
1738
1753
{
1739
- var presenter = this . FindDescendantOfType < ThemedTextDiffPresenter > ( ) ;
1740
- if ( presenter == null )
1741
- return ;
1742
-
1743
- presenter . GotoPrevChange ( ) ;
1744
- if ( presenter is SingleSideTextDiffPresenter singleSide )
1745
- singleSide . ForceSyncScrollOffset ( ) ;
1746
-
1747
- BlockNavigationIndicator = BlockNavigation ? . Indicator ?? string . Empty ;
1754
+ this . FindDescendantOfType < ThemedTextDiffPresenter > ( ) ? . GotoPrevChange ( ) ;
1755
+ RaiseEvent ( new RoutedEventArgs ( BlockNavigationChangedEvent ) ) ;
1748
1756
}
1749
1757
1750
1758
public void GotoNextChange ( )
1751
1759
{
1752
- var presenter = this . FindDescendantOfType < ThemedTextDiffPresenter > ( ) ;
1753
- if ( presenter == null )
1754
- return ;
1755
-
1756
- presenter . GotoNextChange ( ) ;
1757
- if ( presenter is SingleSideTextDiffPresenter singleSide )
1758
- singleSide . ForceSyncScrollOffset ( ) ;
1759
-
1760
- BlockNavigationIndicator = BlockNavigation ? . Indicator ?? string . Empty ;
1760
+ this . FindDescendantOfType < ThemedTextDiffPresenter > ( ) ? . GotoNextChange ( ) ;
1761
+ RaiseEvent ( new RoutedEventArgs ( BlockNavigationChangedEvent ) ) ;
1761
1762
}
1762
1763
1763
1764
public void GotoLastChange ( )
1764
1765
{
1765
- var presenter = this . FindDescendantOfType < ThemedTextDiffPresenter > ( ) ;
1766
- if ( presenter == null )
1767
- return ;
1768
-
1769
- presenter . GotoLastChange ( ) ;
1770
- if ( presenter is SingleSideTextDiffPresenter singleSide )
1771
- singleSide . ForceSyncScrollOffset ( ) ;
1772
-
1773
- BlockNavigationIndicator = BlockNavigation ? . Indicator ?? string . Empty ;
1766
+ this . FindDescendantOfType < ThemedTextDiffPresenter > ( ) ? . GotoLastChange ( ) ;
1767
+ RaiseEvent ( new RoutedEventArgs ( BlockNavigationChangedEvent ) ) ;
1774
1768
}
1775
1769
1776
1770
protected override void OnDataContextChanged ( EventArgs e )
@@ -1820,15 +1814,11 @@ private void RefreshContent(Models.TextDiff diff, bool keepScrollOffset = true)
1820
1814
private void RefreshBlockNavigation ( )
1821
1815
{
1822
1816
if ( UseBlockNavigation )
1823
- {
1824
1817
BlockNavigation = new ViewModels . BlockNavigation ( Editor . Content ) ;
1825
- BlockNavigationIndicator = BlockNavigation . Indicator ;
1826
- }
1827
1818
else
1828
- {
1829
1819
BlockNavigation = null ;
1830
- BlockNavigationIndicator = "-/-" ;
1831
- }
1820
+
1821
+ RaiseEvent ( new RoutedEventArgs ( BlockNavigationChangedEvent ) ) ;
1832
1822
}
1833
1823
1834
1824
private void OnStageChunk ( object _1 , RoutedEventArgs _2 )
0 commit comments