Skip to content

Commit 06a7750

Browse files
committed
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 <[email protected]>
1 parent c2187ed commit 06a7750

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/Views/DiffView.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@
122122

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

src/Views/DiffView.axaml.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using Avalonia;
12
using Avalonia.Controls;
23
using Avalonia.Interactivity;
34
using Avalonia.VisualTree;
@@ -40,5 +41,24 @@ private void OnBlockNavigationChanged(object sender, RoutedEventArgs e)
4041
if (sender is TextDiffView textDiff)
4142
BlockNavigationIndicator.Text = textDiff.BlockNavigation?.Indicator ?? string.Empty;
4243
}
44+
45+
private void OnUseFullTextDiffClicked(object sender, RoutedEventArgs e)
46+
{
47+
var textDiffView = this.FindDescendantOfType<TextDiffView>();
48+
if (textDiffView == null)
49+
return;
50+
51+
var presenter = textDiffView.FindDescendantOfType<ThemedTextDiffPresenter>();
52+
if (presenter == null)
53+
return;
54+
55+
if (presenter.DataContext is Models.TextDiff combined)
56+
combined.ScrollOffset = Vector.Zero;
57+
else if (presenter.DataContext is ViewModels.TwoSideTextDiff twoSides)
58+
twoSides.File = string.Empty; // Just to reset `SyncScrollOffset` without affect UI refresh.
59+
60+
(DataContext as ViewModels.DiffContext)?.ToggleFullTextDiff();
61+
e.Handled = true;
62+
}
4363
}
4464
}

0 commit comments

Comments
 (0)