@@ -694,18 +694,6 @@ public override int GetMaxLineNumber()
694694 return 0 ;
695695 }
696696
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-
709697 public override void UpdateSelectedChunk ( double y )
710698 {
711699 var diff = DataContext as Models . TextDiff ;
@@ -822,6 +810,27 @@ public override void UpdateSelectedChunk(double y)
822810 }
823811 }
824812
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+
825834 protected override void OnDataContextChanged ( EventArgs e )
826835 {
827836 base . OnDataContextChanged ( e ) ;
@@ -853,6 +862,16 @@ protected override void OnDataContextChanged(EventArgs e)
853862
854863 GC . Collect ( ) ;
855864 }
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+ }
856875 }
857876
858877 public class SingleSideTextDiffPresenter : ThemedTextDiffPresenter
@@ -1021,8 +1040,6 @@ protected override void OnLoaded(RoutedEventArgs e)
10211040
10221041 protected override void OnUnloaded ( RoutedEventArgs e )
10231042 {
1024- base . OnUnloaded ( e ) ;
1025-
10261043 if ( _scrollViewer != null )
10271044 {
10281045 _scrollViewer . ScrollChanged -= OnTextViewScrollChanged ;
@@ -1032,6 +1049,7 @@ protected override void OnUnloaded(RoutedEventArgs e)
10321049
10331050 TextArea . PointerWheelChanged -= OnTextAreaPointerWheelChanged ;
10341051
1052+ base . OnUnloaded ( e ) ;
10351053 GC . Collect ( ) ;
10361054 }
10371055
@@ -1067,7 +1085,12 @@ protected override void OnDataContextChanged(EventArgs e)
10671085
10681086 private void OnTextViewScrollGotFocus ( object sender , GotFocusEventArgs e )
10691087 {
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+ }
10711094 }
10721095
10731096 private void OnTextViewScrollChanged ( object sender , ScrollChangedEventArgs e )
0 commit comments