77using Avalonia ;
88using Avalonia . Controls ;
99using Avalonia . Controls . Primitives ;
10+ using Avalonia . Input ;
1011using Avalonia . Interactivity ;
1112using Avalonia . Media ;
1213using Avalonia . VisualTree ;
@@ -657,6 +658,7 @@ protected override void OnLoaded(RoutedEventArgs e)
657658
658659 UpdateTextMate ( ) ;
659660
661+ TextArea . PointerWheelChanged += OnTextAreaPointerWheelChanged ;
660662 TextArea . TextView . ContextRequested += OnTextViewContextRequested ;
661663 }
662664
@@ -676,21 +678,20 @@ protected override void OnUnloaded(RoutedEventArgs e)
676678 _textMate = null ;
677679 }
678680
681+ TextArea . PointerWheelChanged -= OnTextAreaPointerWheelChanged ;
679682 TextArea . TextView . ContextRequested -= OnTextViewContextRequested ;
680683
681684 GC . Collect ( ) ;
682685 }
683686
687+ private void OnTextAreaPointerWheelChanged ( object sender , PointerWheelEventArgs e )
688+ {
689+ if ( ! TextArea . IsFocused ) Focus ( ) ;
690+ }
691+
684692 private void OnTextViewScrollChanged ( object sender , ScrollChangedEventArgs e )
685693 {
686- if ( _syncScrollingByOthers )
687- {
688- _syncScrollingByOthers = false ;
689- }
690- else
691- {
692- SetCurrentValue ( SyncScrollOffsetProperty , _scrollViewer . Offset ) ;
693- }
694+ if ( TextArea . IsFocused ) SetCurrentValue ( SyncScrollOffsetProperty , _scrollViewer . Offset ) ;
694695 }
695696
696697 private void OnTextViewContextRequested ( object sender , ContextRequestedEventArgs e )
@@ -754,24 +755,8 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
754755 }
755756 else if ( change . Property == SyncScrollOffsetProperty )
756757 {
757- if ( _scrollViewer == null )
758- return ;
759-
760- var curOffset = _scrollViewer . Offset ;
761- if ( ! curOffset . Equals ( SyncScrollOffset ) )
762- {
763- _syncScrollingByOthers = true ;
764-
765- if ( curOffset . X != SyncScrollOffset . X )
766- {
767- var offset = new Vector ( Math . Min ( _scrollViewer . ScrollBarMaximum . X , SyncScrollOffset . X ) , SyncScrollOffset . Y ) ;
768- _scrollViewer . Offset = offset ;
769- }
770- else
771- {
772- _scrollViewer . Offset = SyncScrollOffset ;
773- }
774- }
758+ if ( _scrollViewer != null )
759+ _scrollViewer . Offset = SyncScrollOffset ;
775760 }
776761 else if ( change . Property == UseSyntaxHighlightingProperty )
777762 {
@@ -813,7 +798,6 @@ private void UpdateTextMate()
813798 private TextMate . Installation _textMate ;
814799 private readonly LineStyleTransformer _lineStyleTransformer = null ;
815800 private ScrollViewer _scrollViewer = null ;
816- private bool _syncScrollingByOthers = false ;
817801 }
818802
819803 public partial class TextDiffView : UserControl
0 commit comments