Skip to content

Commit e17b53d

Browse files
committed
enhance: block-navigation in text diff view
* It is not necessary to re-calculate all the contents when `UseBlockNavigation` changed * Redraw the text view after `block-navigation` has turned off
1 parent 9dd4166 commit e17b53d

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src/Views/TextDiffView.axaml.cs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -719,19 +719,22 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
719719
else if (change.Property == BlockNavigationProperty)
720720
{
721721
var oldValue = change.OldValue as ViewModels.BlockNavigation;
722-
var newValue = change.NewValue as ViewModels.BlockNavigation;
723722
if (oldValue != null)
723+
{
724724
oldValue.PropertyChanged -= OnBlockNavigationPropertyChanged;
725+
if (oldValue.Current != -1)
726+
TextArea?.TextView?.Redraw();
727+
}
728+
729+
var newValue = change.NewValue as ViewModels.BlockNavigation;
725730
if (newValue != null)
726731
newValue.PropertyChanged += OnBlockNavigationPropertyChanged;
727-
728-
InvalidateVisual();
729732
}
730733
}
731734

732735
private void OnBlockNavigationPropertyChanged(object _1, PropertyChangedEventArgs _2)
733736
{
734-
TextArea.TextView.Redraw();
737+
TextArea?.TextView?.Redraw();
735738
}
736739

737740
private void OnTextViewContextRequested(object sender, ContextRequestedEventArgs e)
@@ -1576,7 +1579,7 @@ static TextDiffView()
15761579

15771580
UseBlockNavigationProperty.Changed.AddClassHandler<TextDiffView>((v, _) =>
15781581
{
1579-
v.RefreshContent(v.DataContext as Models.TextDiff, false);
1582+
v.RefreshBlockNavigation();
15801583
});
15811584

15821585
SelectedChunkProperty.Changed.AddClassHandler<TextDiffView>((v, _) =>
@@ -1664,6 +1667,14 @@ private void RefreshContent(Models.TextDiff diff, bool keepScrollOffset = true)
16641667
Editor.Content = diff;
16651668
}
16661669

1670+
RefreshBlockNavigation();
1671+
1672+
IsUnstagedChange = diff.Option.IsUnstaged;
1673+
EnableChunkSelection = diff.Option.WorkingCopyChange != null;
1674+
}
1675+
1676+
private void RefreshBlockNavigation()
1677+
{
16671678
if (UseBlockNavigation)
16681679
{
16691680
BlockNavigation = new ViewModels.BlockNavigation(Editor.Content);
@@ -1674,9 +1685,6 @@ private void RefreshContent(Models.TextDiff diff, bool keepScrollOffset = true)
16741685
BlockNavigation = null;
16751686
BlockNavigationIndicator = "-/-";
16761687
}
1677-
1678-
IsUnstagedChange = diff.Option.IsUnstaged;
1679-
EnableChunkSelection = diff.Option.WorkingCopyChange != null;
16801688
}
16811689

16821690
private void OnStageChunk(object _1, RoutedEventArgs _2)

0 commit comments

Comments
 (0)