@@ -437,8 +437,8 @@ protected override void OnLoaded(RoutedEventArgs e)
437437 base . OnLoaded ( e ) ;
438438
439439 TextArea . TextView . ContextRequested += OnTextViewContextRequested ;
440- TextArea . TextView . PointerEntered += OnTextViewPointerEntered ;
441- TextArea . TextView . PointerMoved += OnTextViewPointerMoved ;
440+ TextArea . TextView . PointerEntered += OnTextViewPointerChanged ;
441+ TextArea . TextView . PointerMoved += OnTextViewPointerChanged ;
442442 TextArea . TextView . PointerWheelChanged += OnTextViewPointerWheelChanged ;
443443
444444 UpdateTextMate ( ) ;
@@ -449,8 +449,8 @@ protected override void OnUnloaded(RoutedEventArgs e)
449449 base . OnUnloaded ( e ) ;
450450
451451 TextArea . TextView . ContextRequested -= OnTextViewContextRequested ;
452- TextArea . TextView . PointerEntered -= OnTextViewPointerEntered ;
453- TextArea . TextView . PointerMoved -= OnTextViewPointerMoved ;
452+ TextArea . TextView . PointerEntered -= OnTextViewPointerChanged ;
453+ TextArea . TextView . PointerMoved -= OnTextViewPointerChanged ;
454454 TextArea . TextView . PointerWheelChanged -= OnTextViewPointerWheelChanged ;
455455
456456 if ( _textMate != null )
@@ -510,35 +510,43 @@ private void OnTextViewContextRequested(object sender, ContextRequestedEventArgs
510510 e . Handled = true ;
511511 }
512512
513- private void OnTextViewPointerEntered ( object sender , PointerEventArgs e )
513+ private void OnTextViewPointerChanged ( object sender , PointerEventArgs e )
514514 {
515515 if ( EnableChunkSelection && sender is TextView view )
516516 {
517- var chunk = SelectedChunk ;
518- if ( chunk != null )
517+ var selection = TextArea . Selection ;
518+ if ( selection == null || selection . IsEmpty )
519519 {
520- var rect = new Rect ( 0 , chunk . Y , Bounds . Width , chunk . Height ) ;
521- if ( rect . Contains ( e . GetPosition ( this ) ) )
522- return ;
523- }
520+ if ( _lastSelectStart != _lastSelectEnd )
521+ {
522+ _lastSelectStart = TextLocation . Empty ;
523+ _lastSelectEnd = TextLocation . Empty ;
524+ }
524525
525- UpdateSelectedChunk ( e . GetPosition ( view ) . Y + view . VerticalOffset ) ;
526- }
527- }
526+ var chunk = SelectedChunk ;
527+ if ( chunk != null )
528+ {
529+ var rect = new Rect ( 0 , chunk . Y , Bounds . Width , chunk . Height ) ;
530+ if ( rect . Contains ( e . GetPosition ( this ) ) )
531+ return ;
532+ }
528533
529- private void OnTextViewPointerMoved ( object sender , PointerEventArgs e )
530- {
531- if ( EnableChunkSelection && sender is TextView view )
532- {
533- var chunk = SelectedChunk ;
534- if ( chunk != null )
534+ UpdateSelectedChunk ( e . GetPosition ( view ) . Y + view . VerticalOffset ) ;
535+ return ;
536+ }
537+
538+ var start = selection . StartPosition . Location ;
539+ var end = selection . EndPosition . Location ;
540+ if ( _lastSelectStart != start || _lastSelectEnd != end )
535541 {
536- var rect = new Rect ( 0 , chunk . Y , Bounds . Width , chunk . Height ) ;
537- if ( rect . Contains ( e . GetPosition ( this ) ) )
538- return ;
542+ _lastSelectStart = start ;
543+ _lastSelectEnd = end ;
544+ UpdateSelectedChunk ( e . GetPosition ( view ) . Y + view . VerticalOffset ) ;
545+ return ;
539546 }
540547
541- UpdateSelectedChunk ( e . GetPosition ( view ) . Y + view . VerticalOffset ) ;
548+ if ( SelectedChunk == null )
549+ UpdateSelectedChunk ( e . GetPosition ( view ) . Y + view . VerticalOffset ) ;
542550 }
543551 }
544552
@@ -657,7 +665,9 @@ private void UpdateTextMate()
657665 }
658666
659667 private TextMate . Installation _textMate = null ;
660- protected LineStyleTransformer _lineStyleTransformer = null ;
668+ private TextLocation _lastSelectStart = TextLocation . Empty ;
669+ private TextLocation _lastSelectEnd = TextLocation . Empty ;
670+ private LineStyleTransformer _lineStyleTransformer = null ;
661671 }
662672
663673 public class CombinedTextDiffPresenter : ThemedTextDiffPresenter
0 commit comments