Skip to content

Commit 63affef

Browse files
committed
enhance: auto-scroll to selected commit
Signed-off-by: leo <[email protected]>
1 parent af1788e commit 63affef

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

src/Views/Histories.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
RowHeight="26"
4141
HorizontalScrollBarVisibility="Disabled"
4242
VerticalScrollBarVisibility="Auto"
43+
Loaded="OnCommitListLoaded"
4344
LayoutUpdated="OnCommitListLayoutUpdated"
4445
SelectionChanged="OnCommitListSelectionChanged"
4546
ContextRequested="OnCommitListContextRequested"

src/Views/Histories.axaml.cs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Avalonia.Collections;
66
using Avalonia.Controls;
77
using Avalonia.Input;
8+
using Avalonia.Interactivity;
89
using Avalonia.VisualTree;
910

1011
namespace SourceGit.Views
@@ -129,35 +130,37 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
129130

130131
if (change.Property == NavigationIdProperty)
131132
{
132-
var list = CommitListContainer;
133-
if (list is { SelectedItems.Count: 1 })
134-
list.ScrollIntoView(list.SelectedItem, null);
133+
if (CommitListContainer is { SelectedItems.Count: 1, IsLoaded: true } dataGrid)
134+
dataGrid.ScrollIntoView(dataGrid.SelectedItem, null);
135135
}
136136
}
137137

138+
private void OnCommitListLoaded(object sender, RoutedEventArgs e)
139+
{
140+
if (CommitListContainer is { SelectedItems.Count: 1 } dataGrid)
141+
dataGrid.ScrollIntoView(dataGrid.SelectedItem, null);
142+
}
143+
138144
private void OnCommitListLayoutUpdated(object _1, EventArgs _2)
139145
{
140146
if (IsLoaded)
141-
{
142147
CommitGraph.InvalidateVisual();
143-
}
144148
}
145149

146150
private void OnCommitListSelectionChanged(object _, SelectionChangedEventArgs e)
147151
{
148152
if (DataContext is ViewModels.Histories histories)
149-
{
150153
histories.Select(CommitListContainer.SelectedItems);
151-
}
154+
152155
e.Handled = true;
153156
}
154157

155158
private void OnCommitListContextRequested(object sender, ContextRequestedEventArgs e)
156159
{
157-
if (DataContext is ViewModels.Histories histories && sender is DataGrid { SelectedItems.Count: > 0 } list)
160+
if (DataContext is ViewModels.Histories histories && sender is DataGrid { SelectedItems.Count: > 0 } dataGrid)
158161
{
159-
var menu = histories.MakeContextMenu(list);
160-
menu?.Open(list);
162+
var menu = histories.MakeContextMenu(dataGrid);
163+
menu?.Open(dataGrid);
161164
}
162165
e.Handled = true;
163166
}

0 commit comments

Comments
 (0)