Skip to content

Commit 9a4f928

Browse files
committed
fix: DataGrid does NOT scroll when navigation target is the same as current selected in Views.Histories. (#58)
1 parent d09e81b commit 9a4f928

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/ViewModels/Histories.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ public Models.Commit AutoSelectedCommit
6161
private set => SetProperty(ref _autoSelectedCommit, value);
6262
}
6363

64+
public long NavigationId
65+
{
66+
get => _navigationId;
67+
private set => SetProperty(ref _navigationId, value);
68+
}
69+
6470
public object DetailContext
6571
{
6672
get => _detailContext;
@@ -98,6 +104,7 @@ public void NavigateTo(string commitSHA)
98104
if (commit != null)
99105
{
100106
AutoSelectedCommit = commit;
107+
NavigationId = _navigationId + 1;
101108

102109
if (_detailContext is CommitDetail detail)
103110
{
@@ -597,6 +604,7 @@ private void FillTagMenu(ContextMenu menu, Models.Tag tag)
597604
private List<Models.Commit> _commits = new List<Models.Commit>();
598605
private Models.CommitGraph _graph = null;
599606
private Models.Commit _autoSelectedCommit = null;
607+
private long _navigationId = 0;
600608
private object _detailContext = null;
601609
}
602610
}

src/Views/Histories.axaml.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Avalonia;
44
using Avalonia.Controls;
55
using Avalonia.Controls.Primitives;
6+
using Avalonia.Data;
67
using Avalonia.Media;
78
using Avalonia.VisualTree;
89

@@ -258,9 +259,31 @@ private void DrawCurves(DrawingContext context, double top, double bottom)
258259

259260
public partial class Histories : UserControl
260261
{
262+
public static readonly StyledProperty<long> NavigationIdProperty =
263+
AvaloniaProperty.Register<Histories, long>(nameof(NavigationId), 0);
264+
265+
public long NavigationId
266+
{
267+
get => GetValue(NavigationIdProperty);
268+
set => SetValue(NavigationIdProperty, value);
269+
}
270+
271+
static Histories()
272+
{
273+
NavigationIdProperty.Changed.AddClassHandler<Histories>((h, _) =>
274+
{
275+
// Force scroll selected item (current head) into view. see issue #58
276+
var datagrid = h.commitDataGrid;
277+
if (datagrid != null && datagrid.SelectedItems.Count == 1)
278+
datagrid.ScrollIntoView(datagrid.SelectedItems[0], null);
279+
});
280+
}
281+
261282
public Histories()
262283
{
263284
InitializeComponent();
285+
286+
this.Bind(NavigationIdProperty, new Binding("NavigationId", BindingMode.OneWay));
264287
}
265288

266289
private void OnCommitDataGridLayoutUpdated(object sender, EventArgs e)

0 commit comments

Comments
 (0)