@@ -336,6 +336,15 @@ public bool ShowHiddenSymbols
336
336
set => SetValue ( ShowHiddenSymbolsProperty , value ) ;
337
337
}
338
338
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
+
339
348
public static readonly StyledProperty < TextDiffViewChunk > SelectedChunkProperty =
340
349
AvaloniaProperty . Register < ThemedTextDiffPresenter , TextDiffViewChunk > ( nameof ( SelectedChunk ) ) ;
341
350
@@ -479,13 +488,13 @@ private void OnTextViewContextRequested(object sender, ContextRequestedEventArgs
479
488
480
489
private void OnTextViewPointerMoved ( object sender , PointerEventArgs e )
481
490
{
482
- if ( sender is TextView view )
491
+ if ( EnableChunkSelection && sender is TextView view )
483
492
UpdateSelectedChunk ( e . GetPosition ( view ) . Y + view . VerticalOffset ) ;
484
493
}
485
494
486
495
private void OnTextViewPointerWheelChanged ( object sender , PointerWheelEventArgs e )
487
496
{
488
- if ( sender is TextView view )
497
+ if ( EnableChunkSelection && sender is TextView view )
489
498
{
490
499
var y = e . GetPosition ( view ) . Y + view . VerticalOffset ;
491
500
Dispatcher . UIThread . Post ( ( ) => UpdateSelectedChunk ( y ) ) ;
@@ -636,7 +645,7 @@ protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
636
645
public override void UpdateSelectedChunk ( double y )
637
646
{
638
647
var diff = DataContext as Models . TextDiff ;
639
- if ( diff == null || diff . Option . WorkingCopyChange == null )
648
+ if ( diff == null )
640
649
return ;
641
650
642
651
var view = TextArea . TextView ;
@@ -796,7 +805,7 @@ public override int GetMaxLineNumber()
796
805
public override void UpdateSelectedChunk ( double y )
797
806
{
798
807
var diff = DataContext as ViewModels . TwoSideTextDiff ;
799
- if ( diff == null || diff . Option . WorkingCopyChange == null )
808
+ if ( diff == null )
800
809
return ;
801
810
802
811
var parent = this . FindAncestorOfType < TextDiffView > ( ) ;
@@ -1012,6 +1021,15 @@ public bool IsUnstagedChange
1012
1021
set => SetValue ( IsUnstagedChangeProperty , value ) ;
1013
1022
}
1014
1023
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
+
1015
1033
static TextDiffView ( )
1016
1034
{
1017
1035
UseSideBySideDiffProperty . Changed . AddClassHandler < TextDiffView > ( ( v , _ ) =>
@@ -1069,6 +1087,7 @@ protected override void OnDataContextChanged(EventArgs e)
1069
1087
Editor . Content = diff ;
1070
1088
1071
1089
IsUnstagedChange = diff . Option . IsUnstaged ;
1090
+ EnableChunkSelection = diff . Option . WorkingCopyChange != null ;
1072
1091
}
1073
1092
1074
1093
protected override void OnPointerExited ( PointerEventArgs e )
@@ -1160,8 +1179,6 @@ private void OnUnstageChunk(object sender, RoutedEventArgs e)
1160
1179
if ( ! selection . HasChanges )
1161
1180
return ;
1162
1181
1163
- // If all changes has been selected the use method provided by ViewModels.WorkingCopy.
1164
- // Otherwise, use `git apply`
1165
1182
if ( ! selection . HasLeftChanges )
1166
1183
{
1167
1184
var workcopyView = this . FindAncestorOfType < WorkingCopy > ( ) ;
@@ -1218,8 +1235,6 @@ private void OnDiscardChunk(object sender, RoutedEventArgs e)
1218
1235
if ( ! selection . HasChanges )
1219
1236
return ;
1220
1237
1221
- // If all changes has been selected the use method provided by ViewModels.WorkingCopy.
1222
- // Otherwise, use `git apply`
1223
1238
if ( ! selection . HasLeftChanges )
1224
1239
{
1225
1240
var workcopyView = this . FindAncestorOfType < WorkingCopy > ( ) ;
0 commit comments