From 06a77502bc753c38a769b17a7693270771506323 Mon Sep 17 00:00:00 2001 From: leo Date: Wed, 4 Jun 2025 13:13:28 +0800 Subject: [PATCH] fix: crash when clicking `Previous Difference` without visual lines (#1385) Always scroll to top when the state of `Show All Lines` changed Signed-off-by: leo --- src/Views/DiffView.axaml | 2 +- src/Views/DiffView.axaml.cs | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Views/DiffView.axaml b/src/Views/DiffView.axaml index 85da69d1..559ad14d 100644 --- a/src/Views/DiffView.axaml +++ b/src/Views/DiffView.axaml @@ -122,7 +122,7 @@ diff --git a/src/Views/DiffView.axaml.cs b/src/Views/DiffView.axaml.cs index 9dd27f24..54f9617a 100644 --- a/src/Views/DiffView.axaml.cs +++ b/src/Views/DiffView.axaml.cs @@ -1,3 +1,4 @@ +using Avalonia; using Avalonia.Controls; using Avalonia.Interactivity; using Avalonia.VisualTree; @@ -40,5 +41,24 @@ namespace SourceGit.Views if (sender is TextDiffView textDiff) BlockNavigationIndicator.Text = textDiff.BlockNavigation?.Indicator ?? string.Empty; } + + private void OnUseFullTextDiffClicked(object sender, RoutedEventArgs e) + { + var textDiffView = this.FindDescendantOfType(); + if (textDiffView == null) + return; + + var presenter = textDiffView.FindDescendantOfType(); + if (presenter == null) + return; + + if (presenter.DataContext is Models.TextDiff combined) + combined.ScrollOffset = Vector.Zero; + else if (presenter.DataContext is ViewModels.TwoSideTextDiff twoSides) + twoSides.File = string.Empty; // Just to reset `SyncScrollOffset` without affect UI refresh. + + (DataContext as ViewModels.DiffContext)?.ToggleFullTextDiff(); + e.Handled = true; + } } }