@@ -694,18 +694,6 @@ public override int GetMaxLineNumber()
694
694
return 0 ;
695
695
}
696
696
697
- protected override void OnApplyTemplate ( TemplateAppliedEventArgs e )
698
- {
699
- base . OnApplyTemplate ( e ) ;
700
-
701
- var scroller = ( ScrollViewer ) e . NameScope . Find ( "PART_ScrollViewer" ) ;
702
- if ( scroller != null )
703
- {
704
- scroller . Bind ( ScrollViewer . OffsetProperty , new Binding ( "SyncScrollOffset" , BindingMode . TwoWay ) ) ;
705
- scroller . GotFocus += ( _ , _ ) => TrySetChunk ( null ) ;
706
- }
707
- }
708
-
709
697
public override void UpdateSelectedChunk ( double y )
710
698
{
711
699
var diff = DataContext as Models . TextDiff ;
@@ -822,6 +810,27 @@ public override void UpdateSelectedChunk(double y)
822
810
}
823
811
}
824
812
813
+ protected override void OnLoaded ( RoutedEventArgs e )
814
+ {
815
+ base . OnLoaded ( e ) ;
816
+
817
+ var scroller = this . FindDescendantOfType < ScrollViewer > ( ) ;
818
+ if ( scroller != null )
819
+ {
820
+ scroller . Bind ( ScrollViewer . OffsetProperty , new Binding ( "SyncScrollOffset" , BindingMode . TwoWay ) ) ;
821
+ scroller . GotFocus += OnTextViewScrollGotFocus ;
822
+ }
823
+ }
824
+
825
+ protected override void OnUnloaded ( RoutedEventArgs e )
826
+ {
827
+ var scroller = this . FindDescendantOfType < ScrollViewer > ( ) ;
828
+ if ( scroller != null )
829
+ scroller . GotFocus -= OnTextViewScrollGotFocus ;
830
+
831
+ base . OnUnloaded ( e ) ;
832
+ }
833
+
825
834
protected override void OnDataContextChanged ( EventArgs e )
826
835
{
827
836
base . OnDataContextChanged ( e ) ;
@@ -853,6 +862,16 @@ protected override void OnDataContextChanged(EventArgs e)
853
862
854
863
GC . Collect ( ) ;
855
864
}
865
+
866
+ private void OnTextViewScrollGotFocus ( object sender , GotFocusEventArgs e )
867
+ {
868
+ if ( EnableChunkSelection && sender is ScrollViewer viewer )
869
+ {
870
+ var area = viewer . FindDescendantOfType < TextArea > ( ) ;
871
+ if ( ! area . IsPointerOver )
872
+ TrySetChunk ( null ) ;
873
+ }
874
+ }
856
875
}
857
876
858
877
public class SingleSideTextDiffPresenter : ThemedTextDiffPresenter
@@ -1021,8 +1040,6 @@ protected override void OnLoaded(RoutedEventArgs e)
1021
1040
1022
1041
protected override void OnUnloaded ( RoutedEventArgs e )
1023
1042
{
1024
- base . OnUnloaded ( e ) ;
1025
-
1026
1043
if ( _scrollViewer != null )
1027
1044
{
1028
1045
_scrollViewer . ScrollChanged -= OnTextViewScrollChanged ;
@@ -1032,6 +1049,7 @@ protected override void OnUnloaded(RoutedEventArgs e)
1032
1049
1033
1050
TextArea . PointerWheelChanged -= OnTextAreaPointerWheelChanged ;
1034
1051
1052
+ base . OnUnloaded ( e ) ;
1035
1053
GC . Collect ( ) ;
1036
1054
}
1037
1055
@@ -1067,7 +1085,12 @@ protected override void OnDataContextChanged(EventArgs e)
1067
1085
1068
1086
private void OnTextViewScrollGotFocus ( object sender , GotFocusEventArgs e )
1069
1087
{
1070
- TrySetChunk ( null ) ;
1088
+ if ( EnableChunkSelection && sender is ScrollViewer viewer )
1089
+ {
1090
+ var area = viewer . FindDescendantOfType < TextArea > ( ) ;
1091
+ if ( ! area . IsPointerOver )
1092
+ TrySetChunk ( null ) ;
1093
+ }
1071
1094
}
1072
1095
1073
1096
private void OnTextViewScrollChanged ( object sender , ScrollChangedEventArgs e )
0 commit comments