fix<Diff, Blame>: check scroller before use it

This commit is contained in:
leo 2020-11-26 12:47:24 +08:00
parent f1b31820a7
commit 757c64e49c
2 changed files with 11 additions and 3 deletions

View file

@ -171,7 +171,7 @@ namespace SourceGit.UI {
var minWidth = total - offset; var minWidth = total - offset;
var scroller = GetVisualChild<ScrollViewer>(blame); var scroller = GetVisualChild<ScrollViewer>(blame);
if (scroller.ComputedVerticalScrollBarVisibility == Visibility.Visible) minWidth -= 8; if (scroller != null && scroller.ComputedVerticalScrollBarVisibility == Visibility.Visible) minWidth -= 8;
blame.Columns[1].MinWidth = minWidth; blame.Columns[1].MinWidth = minWidth;
blame.Columns[1].Width = DataGridLength.SizeToCells; blame.Columns[1].Width = DataGridLength.SizeToCells;

View file

@ -466,12 +466,16 @@ namespace SourceGit.UI {
if (e.VerticalChange != 0) { if (e.VerticalChange != 0) {
foreach (var editor in editors) { foreach (var editor in editors) {
var scroller = GetVisualChild<ScrollViewer>(editor); var scroller = GetVisualChild<ScrollViewer>(editor);
if (scroller.VerticalOffset != e.VerticalOffset) scroller.ScrollToVerticalOffset(e.VerticalOffset); if (scroller != null && scroller.VerticalOffset != e.VerticalOffset) {
scroller.ScrollToVerticalOffset(e.VerticalOffset);
}
} }
} else { } else {
foreach (var editor in editors) { foreach (var editor in editors) {
var scroller = GetVisualChild<ScrollViewer>(editor); var scroller = GetVisualChild<ScrollViewer>(editor);
if (scroller.HorizontalOffset != e.HorizontalOffset) scroller.ScrollToHorizontalOffset(e.HorizontalOffset); if (scroller != null && scroller.HorizontalOffset != e.HorizontalOffset) {
scroller.ScrollToHorizontalOffset(e.HorizontalOffset);
}
} }
} }
} }
@ -486,6 +490,8 @@ namespace SourceGit.UI {
var grid = editors[0]; var grid = editors[0];
var scroller = GetVisualChild<ScrollViewer>(grid); var scroller = GetVisualChild<ScrollViewer>(grid);
if (scroller == null) return;
var firstVisible = (int)scroller.VerticalOffset; var firstVisible = (int)scroller.VerticalOffset;
var firstModeEnded = false; var firstModeEnded = false;
var first = grid.Items[firstVisible] as ChangeBlock; var first = grid.Items[firstVisible] as ChangeBlock;
@ -512,6 +518,8 @@ namespace SourceGit.UI {
var grid = editors[0]; var grid = editors[0];
var scroller = GetVisualChild<ScrollViewer>(grid); var scroller = GetVisualChild<ScrollViewer>(grid);
if (scroller == null) return;
var firstVisible = (int)scroller.VerticalOffset; var firstVisible = (int)scroller.VerticalOffset;
var firstModeEnded = false; var firstModeEnded = false;
var first = grid.Items[firstVisible] as ChangeBlock; var first = grid.Items[firstVisible] as ChangeBlock;