fix: crash when clicking Previous Difference without visual lines (#1385)
Some checks are pending
Continuous Integration / Build (push) Waiting to run
Continuous Integration / Prepare version string (push) Waiting to run
Continuous Integration / Package (push) Blocked by required conditions

Always scroll to top when the state of `Show All Lines` changed

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo 2025-06-04 13:13:28 +08:00
parent c2187edbe9
commit 06a77502bc
No known key found for this signature in database
2 changed files with 21 additions and 1 deletions

View file

@ -122,7 +122,7 @@
<ToggleButton Classes="line_path"
Width="28"
Command="{Binding ToggleFullTextDiff}"
Click="OnUseFullTextDiffClicked"
IsChecked="{Binding Source={x:Static vm:Preferences.Instance}, Path=UseFullTextDiff, Mode=OneWay}"
IsVisible="{Binding IsTextDiff}"
ToolTip.Tip="{DynamicResource Text.Diff.VisualLines.All}">

View file

@ -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<TextDiffView>();
if (textDiffView == null)
return;
var presenter = textDiffView.FindDescendantOfType<ThemedTextDiffPresenter>();
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;
}
}
}