diff --git a/src/Views/DiffView.axaml b/src/Views/DiffView.axaml
index 12cfa451..c4da158d 100644
--- a/src/Views/DiffView.axaml
+++ b/src/Views/DiffView.axaml
@@ -285,10 +285,9 @@
-
+
diff --git a/src/Views/DiffView.axaml.cs b/src/Views/DiffView.axaml.cs
index 889f0df7..f0824307 100644
--- a/src/Views/DiffView.axaml.cs
+++ b/src/Views/DiffView.axaml.cs
@@ -13,30 +13,32 @@ namespace SourceGit.Views
private void OnGotoFirstChange(object _, RoutedEventArgs e)
{
- var textDiff = this.FindDescendantOfType();
- textDiff?.GotoFirstChange();
+ this.FindDescendantOfType()?.GotoFirstChange();
e.Handled = true;
}
private void OnGotoPrevChange(object _, RoutedEventArgs e)
{
- var textDiff = this.FindDescendantOfType();
- textDiff?.GotoPrevChange();
+ this.FindDescendantOfType()?.GotoPrevChange();
e.Handled = true;
}
private void OnGotoNextChange(object _, RoutedEventArgs e)
{
- var textDiff = this.FindDescendantOfType();
- textDiff?.GotoNextChange();
+ this.FindDescendantOfType()?.GotoNextChange();
e.Handled = true;
}
private void OnGotoLastChange(object _, RoutedEventArgs e)
{
- var textDiff = this.FindDescendantOfType();
- textDiff?.GotoLastChange();
+ this.FindDescendantOfType()?.GotoLastChange();
e.Handled = true;
}
+
+ private void OnBlockNavigationChanged(object sender, RoutedEventArgs e)
+ {
+ if (sender is TextDiffView { UseBlockNavigation: true } textDiff)
+ BlockNavigationIndicator.Text = textDiff.BlockNavigation?.Indicator ?? string.Empty;
+ }
}
}
diff --git a/src/Views/TextDiffView.axaml.cs b/src/Views/TextDiffView.axaml.cs
index 0d20a990..7b461e57 100644
--- a/src/Views/TextDiffView.axaml.cs
+++ b/src/Views/TextDiffView.axaml.cs
@@ -553,7 +553,7 @@ namespace SourceGit.Views
{
}
- public void GotoFirstChange()
+ public virtual void GotoFirstChange()
{
var blockNavigation = BlockNavigation;
if (blockNavigation != null)
@@ -567,7 +567,7 @@ namespace SourceGit.Views
}
}
- public void GotoPrevChange()
+ public virtual void GotoPrevChange()
{
var blockNavigation = BlockNavigation;
if (blockNavigation != null)
@@ -623,7 +623,7 @@ namespace SourceGit.Views
}
}
- public void GotoNextChange()
+ public virtual void GotoNextChange()
{
var blockNavigation = BlockNavigation;
if (blockNavigation != null)
@@ -665,7 +665,7 @@ namespace SourceGit.Views
}
}
- public void GotoLastChange()
+ public virtual void GotoLastChange()
{
var blockNavigation = BlockNavigation;
if (blockNavigation != null)
@@ -766,15 +766,13 @@ namespace SourceGit.Views
{
var oldValue = change.OldValue as ViewModels.BlockNavigation;
if (oldValue != null)
- {
oldValue.PropertyChanged -= OnBlockNavigationPropertyChanged;
- if (oldValue.Current != -1)
- TextArea?.TextView?.Redraw();
- }
var newValue = change.NewValue as ViewModels.BlockNavigation;
if (newValue != null)
newValue.PropertyChanged += OnBlockNavigationPropertyChanged;
+
+ TextArea?.TextView?.Redraw();
}
}
@@ -793,9 +791,10 @@ namespace SourceGit.Views
base.OnKeyDown(e);
}
- private void OnBlockNavigationPropertyChanged(object _1, PropertyChangedEventArgs _2)
+ private void OnBlockNavigationPropertyChanged(object _1, PropertyChangedEventArgs e)
{
- TextArea?.TextView?.Redraw();
+ if (e.PropertyName == "Current")
+ TextArea?.TextView?.Redraw();
}
private void OnTextViewContextRequested(object sender, ContextRequestedEventArgs e)
@@ -1223,19 +1222,18 @@ namespace SourceGit.Views
{
base.OnLoaded(e);
- var scroller = this.FindDescendantOfType();
- if (scroller != null)
+ _scrollViewer = this.FindDescendantOfType();
+ if (_scrollViewer != null)
{
- scroller.Bind(ScrollViewer.OffsetProperty, new Binding("ScrollOffset", BindingMode.TwoWay));
- scroller.ScrollChanged += OnTextViewScrollChanged;
+ _scrollViewer.Bind(ScrollViewer.OffsetProperty, new Binding("ScrollOffset", BindingMode.TwoWay));
+ _scrollViewer.ScrollChanged += OnTextViewScrollChanged;
}
}
protected override void OnUnloaded(RoutedEventArgs e)
{
- var scroller = this.FindDescendantOfType();
- if (scroller != null)
- scroller.ScrollChanged -= OnTextViewScrollChanged;
+ if (_scrollViewer != null)
+ _scrollViewer.ScrollChanged -= OnTextViewScrollChanged;
base.OnUnloaded(e);
}
@@ -1274,9 +1272,11 @@ namespace SourceGit.Views
private void OnTextViewScrollChanged(object sender, ScrollChangedEventArgs e)
{
- if (sender is ScrollViewer { IsExpanded: true, IsPointerOver: true } scroller)
+ if (_scrollViewer is { IsExpanded: true, IsPointerOver: true })
TrySetChunk(null);
}
+
+ private ScrollViewer _scrollViewer = null;
}
public class SingleSideTextDiffPresenter : ThemedTextDiffPresenter
@@ -1288,14 +1288,6 @@ namespace SourceGit.Views
TextArea.LeftMargins.Add(new LineModifyTypeMargin());
}
- public void ForceSyncScrollOffset()
- {
- if (_scrollViewer == null)
- return;
- if (DataContext is ViewModels.TwoSideTextDiff diff)
- diff.SyncScrollOffset = _scrollViewer?.Offset ?? Vector.Zero;
- }
-
public override List GetLines()
{
if (DataContext is ViewModels.TwoSideTextDiff diff)
@@ -1310,6 +1302,30 @@ namespace SourceGit.Views
return 0;
}
+ public override void GotoFirstChange()
+ {
+ base.GotoFirstChange();
+ DirectSyncScrollOffset();
+ }
+
+ public override void GotoPrevChange()
+ {
+ base.GotoPrevChange();
+ DirectSyncScrollOffset();
+ }
+
+ public override void GotoNextChange()
+ {
+ base.GotoNextChange();
+ DirectSyncScrollOffset();
+ }
+
+ public override void GotoLastChange()
+ {
+ base.GotoLastChange();
+ DirectSyncScrollOffset();
+ }
+
public override void UpdateSelectedChunk(double y)
{
var diff = DataContext as ViewModels.TwoSideTextDiff;
@@ -1497,11 +1513,17 @@ namespace SourceGit.Views
{
diff.SyncScrollOffset = _scrollViewer?.Offset ?? Vector.Zero;
- if (sender is ScrollViewer { IsExpanded: true, IsPointerOver: true } scroller )
+ if (_scrollViewer is { IsExpanded: true, IsPointerOver: true } )
TrySetChunk(null);
}
}
+ private void DirectSyncScrollOffset()
+ {
+ if (_scrollViewer is { } && DataContext is ViewModels.TwoSideTextDiff diff)
+ diff.SyncScrollOffset = _scrollViewer?.Offset ?? Vector.Zero;
+ }
+
private ScrollViewer _scrollViewer = null;
}
@@ -1679,13 +1701,13 @@ namespace SourceGit.Views
set => SetValue(BlockNavigationProperty, value);
}
- public static readonly StyledProperty BlockNavigationIndicatorProperty =
- AvaloniaProperty.Register(nameof(BlockNavigationIndicator));
+ public static readonly RoutedEvent BlockNavigationChangedEvent =
+ RoutedEvent.Register(nameof(BlockNavigationChanged), RoutingStrategies.Tunnel | RoutingStrategies.Bubble);
- public string BlockNavigationIndicator
+ public event EventHandler BlockNavigationChanged
{
- get => GetValue(BlockNavigationIndicatorProperty);
- set => SetValue(BlockNavigationIndicatorProperty, value);
+ add { AddHandler(BlockNavigationChangedEvent, value); }
+ remove { RemoveHandler(BlockNavigationChangedEvent, value); }
}
static TextDiffView()
@@ -1723,54 +1745,26 @@ namespace SourceGit.Views
public void GotoFirstChange()
{
- var presenter = this.FindDescendantOfType();
- if (presenter == null)
- return;
-
- presenter.GotoFirstChange();
- if (presenter is SingleSideTextDiffPresenter singleSide)
- singleSide.ForceSyncScrollOffset();
-
- BlockNavigationIndicator = BlockNavigation?.Indicator ?? string.Empty;
+ this.FindDescendantOfType()?.GotoFirstChange();
+ RaiseEvent(new RoutedEventArgs(BlockNavigationChangedEvent));
}
public void GotoPrevChange()
{
- var presenter = this.FindDescendantOfType();
- if (presenter == null)
- return;
-
- presenter.GotoPrevChange();
- if (presenter is SingleSideTextDiffPresenter singleSide)
- singleSide.ForceSyncScrollOffset();
-
- BlockNavigationIndicator = BlockNavigation?.Indicator ?? string.Empty;
+ this.FindDescendantOfType()?.GotoPrevChange();
+ RaiseEvent(new RoutedEventArgs(BlockNavigationChangedEvent));
}
public void GotoNextChange()
{
- var presenter = this.FindDescendantOfType();
- if (presenter == null)
- return;
-
- presenter.GotoNextChange();
- if (presenter is SingleSideTextDiffPresenter singleSide)
- singleSide.ForceSyncScrollOffset();
-
- BlockNavigationIndicator = BlockNavigation?.Indicator ?? string.Empty;
+ this.FindDescendantOfType()?.GotoNextChange();
+ RaiseEvent(new RoutedEventArgs(BlockNavigationChangedEvent));
}
public void GotoLastChange()
{
- var presenter = this.FindDescendantOfType();
- if (presenter == null)
- return;
-
- presenter.GotoLastChange();
- if (presenter is SingleSideTextDiffPresenter singleSide)
- singleSide.ForceSyncScrollOffset();
-
- BlockNavigationIndicator = BlockNavigation?.Indicator ?? string.Empty;
+ this.FindDescendantOfType()?.GotoLastChange();
+ RaiseEvent(new RoutedEventArgs(BlockNavigationChangedEvent));
}
protected override void OnDataContextChanged(EventArgs e)
@@ -1820,15 +1814,11 @@ namespace SourceGit.Views
private void RefreshBlockNavigation()
{
if (UseBlockNavigation)
- {
BlockNavigation = new ViewModels.BlockNavigation(Editor.Content);
- BlockNavigationIndicator = BlockNavigation.Indicator;
- }
else
- {
BlockNavigation = null;
- BlockNavigationIndicator = "-/-";
- }
+
+ RaiseEvent(new RoutedEventArgs(BlockNavigationChangedEvent));
}
private void OnStageChunk(object _1, RoutedEventArgs _2)