From d335cac167e817c2581921259ca40569f605d855 Mon Sep 17 00:00:00 2001 From: leo Date: Fri, 21 Mar 2025 18:00:46 +0800 Subject: [PATCH] enhance: only raise `BlockNavigationChangedEvent` when `UseBlockNavigation` enabled Signed-off-by: leo --- src/Views/DiffView.axaml.cs | 2 +- src/Views/TextDiffView.axaml.cs | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/Views/DiffView.axaml.cs b/src/Views/DiffView.axaml.cs index f0824307..9dd27f24 100644 --- a/src/Views/DiffView.axaml.cs +++ b/src/Views/DiffView.axaml.cs @@ -37,7 +37,7 @@ namespace SourceGit.Views private void OnBlockNavigationChanged(object sender, RoutedEventArgs e) { - if (sender is TextDiffView { UseBlockNavigation: true } textDiff) + if (sender is TextDiffView textDiff) BlockNavigationIndicator.Text = textDiff.BlockNavigation?.Indicator ?? string.Empty; } } diff --git a/src/Views/TextDiffView.axaml.cs b/src/Views/TextDiffView.axaml.cs index c55719de..7ce9f288 100644 --- a/src/Views/TextDiffView.axaml.cs +++ b/src/Views/TextDiffView.axaml.cs @@ -1746,25 +1746,25 @@ namespace SourceGit.Views public void GotoFirstChange() { this.FindDescendantOfType()?.GotoFirstChange(); - RaiseEvent(new RoutedEventArgs(BlockNavigationChangedEvent)); + TryRaiseBlockNavigationChanged(); } public void GotoPrevChange() { this.FindDescendantOfType()?.GotoPrevChange(); - RaiseEvent(new RoutedEventArgs(BlockNavigationChangedEvent)); + TryRaiseBlockNavigationChanged(); } public void GotoNextChange() { this.FindDescendantOfType()?.GotoNextChange(); - RaiseEvent(new RoutedEventArgs(BlockNavigationChangedEvent)); + TryRaiseBlockNavigationChanged(); } public void GotoLastChange() { this.FindDescendantOfType()?.GotoLastChange(); - RaiseEvent(new RoutedEventArgs(BlockNavigationChangedEvent)); + TryRaiseBlockNavigationChanged(); } protected override void OnDataContextChanged(EventArgs e) @@ -1818,7 +1818,7 @@ namespace SourceGit.Views else BlockNavigation = null; - RaiseEvent(new RoutedEventArgs(BlockNavigationChangedEvent)); + TryRaiseBlockNavigationChanged(); } private void OnStageChunk(object _1, RoutedEventArgs _2) @@ -1990,5 +1990,11 @@ namespace SourceGit.Views repo.MarkWorkingCopyDirtyManually(); repo.SetWatcherEnabled(true); } + + private void TryRaiseBlockNavigationChanged() + { + if (UseBlockNavigation) + RaiseEvent(new RoutedEventArgs(BlockNavigationChangedEvent)); + } } }