diff --git a/src/ViewModels/Histories.cs b/src/ViewModels/Histories.cs index 2c23d44a..bf119eac 100644 --- a/src/ViewModels/Histories.cs +++ b/src/ViewModels/Histories.cs @@ -61,6 +61,12 @@ namespace SourceGit.ViewModels private set => SetProperty(ref _autoSelectedCommit, value); } + public long NavigationId + { + get => _navigationId; + private set => SetProperty(ref _navigationId, value); + } + public object DetailContext { get => _detailContext; @@ -98,6 +104,7 @@ namespace SourceGit.ViewModels if (commit != null) { AutoSelectedCommit = commit; + NavigationId = _navigationId + 1; if (_detailContext is CommitDetail detail) { @@ -597,6 +604,7 @@ namespace SourceGit.ViewModels private List _commits = new List(); private Models.CommitGraph _graph = null; private Models.Commit _autoSelectedCommit = null; + private long _navigationId = 0; private object _detailContext = null; } } diff --git a/src/Views/Histories.axaml.cs b/src/Views/Histories.axaml.cs index b22d4e04..16ca541c 100644 --- a/src/Views/Histories.axaml.cs +++ b/src/Views/Histories.axaml.cs @@ -3,6 +3,7 @@ using System; using Avalonia; using Avalonia.Controls; using Avalonia.Controls.Primitives; +using Avalonia.Data; using Avalonia.Media; using Avalonia.VisualTree; @@ -258,9 +259,31 @@ namespace SourceGit.Views public partial class Histories : UserControl { + public static readonly StyledProperty NavigationIdProperty = + AvaloniaProperty.Register(nameof(NavigationId), 0); + + public long NavigationId + { + get => GetValue(NavigationIdProperty); + set => SetValue(NavigationIdProperty, value); + } + + static Histories() + { + NavigationIdProperty.Changed.AddClassHandler((h, _) => + { + // Force scroll selected item (current head) into view. see issue #58 + var datagrid = h.commitDataGrid; + if (datagrid != null && datagrid.SelectedItems.Count == 1) + datagrid.ScrollIntoView(datagrid.SelectedItems[0], null); + }); + } + public Histories() { InitializeComponent(); + + this.Bind(NavigationIdProperty, new Binding("NavigationId", BindingMode.OneWay)); } private void OnCommitDataGridLayoutUpdated(object sender, EventArgs e)