@@ -336,6 +336,15 @@ public bool ShowHiddenSymbols
336336 set => SetValue ( ShowHiddenSymbolsProperty , value ) ;
337337 }
338338
339+ public static readonly StyledProperty < bool > EnableChunkSelectionProperty =
340+ AvaloniaProperty . Register < ThemedTextDiffPresenter , bool > ( nameof ( EnableChunkSelection ) ) ;
341+
342+ public bool EnableChunkSelection
343+ {
344+ get => GetValue ( EnableChunkSelectionProperty ) ;
345+ set => SetValue ( EnableChunkSelectionProperty , value ) ;
346+ }
347+
339348 public static readonly StyledProperty < TextDiffViewChunk > SelectedChunkProperty =
340349 AvaloniaProperty . Register < ThemedTextDiffPresenter , TextDiffViewChunk > ( nameof ( SelectedChunk ) ) ;
341350
@@ -479,13 +488,13 @@ private void OnTextViewContextRequested(object sender, ContextRequestedEventArgs
479488
480489 private void OnTextViewPointerMoved ( object sender , PointerEventArgs e )
481490 {
482- if ( sender is TextView view )
491+ if ( EnableChunkSelection && sender is TextView view )
483492 UpdateSelectedChunk ( e . GetPosition ( view ) . Y + view . VerticalOffset ) ;
484493 }
485494
486495 private void OnTextViewPointerWheelChanged ( object sender , PointerWheelEventArgs e )
487496 {
488- if ( sender is TextView view )
497+ if ( EnableChunkSelection && sender is TextView view )
489498 {
490499 var y = e . GetPosition ( view ) . Y + view . VerticalOffset ;
491500 Dispatcher . UIThread . Post ( ( ) => UpdateSelectedChunk ( y ) ) ;
@@ -636,7 +645,7 @@ protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
636645 public override void UpdateSelectedChunk ( double y )
637646 {
638647 var diff = DataContext as Models . TextDiff ;
639- if ( diff == null || diff . Option . WorkingCopyChange == null )
648+ if ( diff == null )
640649 return ;
641650
642651 var view = TextArea . TextView ;
@@ -796,7 +805,7 @@ public override int GetMaxLineNumber()
796805 public override void UpdateSelectedChunk ( double y )
797806 {
798807 var diff = DataContext as ViewModels . TwoSideTextDiff ;
799- if ( diff == null || diff . Option . WorkingCopyChange == null )
808+ if ( diff == null )
800809 return ;
801810
802811 var parent = this . FindAncestorOfType < TextDiffView > ( ) ;
@@ -1012,6 +1021,15 @@ public bool IsUnstagedChange
10121021 set => SetValue ( IsUnstagedChangeProperty , value ) ;
10131022 }
10141023
1024+ public static readonly StyledProperty < bool > EnableChunkSelectionProperty =
1025+ AvaloniaProperty . Register < TextDiffView , bool > ( nameof ( EnableChunkSelection ) ) ;
1026+
1027+ public bool EnableChunkSelection
1028+ {
1029+ get => GetValue ( EnableChunkSelectionProperty ) ;
1030+ set => SetValue ( EnableChunkSelectionProperty , value ) ;
1031+ }
1032+
10151033 static TextDiffView ( )
10161034 {
10171035 UseSideBySideDiffProperty . Changed . AddClassHandler < TextDiffView > ( ( v , _ ) =>
@@ -1069,6 +1087,7 @@ protected override void OnDataContextChanged(EventArgs e)
10691087 Editor . Content = diff ;
10701088
10711089 IsUnstagedChange = diff . Option . IsUnstaged ;
1090+ EnableChunkSelection = diff . Option . WorkingCopyChange != null ;
10721091 }
10731092
10741093 protected override void OnPointerExited ( PointerEventArgs e )
@@ -1160,8 +1179,6 @@ private void OnUnstageChunk(object sender, RoutedEventArgs e)
11601179 if ( ! selection . HasChanges )
11611180 return ;
11621181
1163- // If all changes has been selected the use method provided by ViewModels.WorkingCopy.
1164- // Otherwise, use `git apply`
11651182 if ( ! selection . HasLeftChanges )
11661183 {
11671184 var workcopyView = this . FindAncestorOfType < WorkingCopy > ( ) ;
@@ -1218,8 +1235,6 @@ private void OnDiscardChunk(object sender, RoutedEventArgs e)
12181235 if ( ! selection . HasChanges )
12191236 return ;
12201237
1221- // If all changes has been selected the use method provided by ViewModels.WorkingCopy.
1222- // Otherwise, use `git apply`
12231238 if ( ! selection . HasLeftChanges )
12241239 {
12251240 var workcopyView = this . FindAncestorOfType < WorkingCopy > ( ) ;
0 commit comments