Skip to content

Commit 6142591

Browse files
committed
ux: auto-focus commits list box and select the first commit on startup
Signed-off-by: leo <[email protected]>
1 parent 8f8ed68 commit 6142591

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

src/ViewModels/InteractiveRebase.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,11 @@ public InteractiveRebase(Repository repo, Models.Branch current, Models.Commit o
129129

130130
Task.Run(async () =>
131131
{
132-
var commits = await new Commands.QueryCommitsForInteractiveRebase(repoPath, on.SHA).GetResultAsync().ConfigureAwait(false);
133-
var list = new List<InteractiveRebaseItem>();
132+
var commits = await new Commands.QueryCommitsForInteractiveRebase(repoPath, on.SHA)
133+
.GetResultAsync()
134+
.ConfigureAwait(false);
134135

136+
var list = new List<InteractiveRebaseItem>();
135137
for (var i = 0; i < commits.Count; i++)
136138
{
137139
var c = commits[i];
@@ -141,6 +143,8 @@ public InteractiveRebase(Repository repo, Models.Branch current, Models.Commit o
141143
Dispatcher.UIThread.Post(() =>
142144
{
143145
Items.AddRange(list);
146+
if (list.Count > 0)
147+
SelectedItem = list[0];
144148
IsLoading = false;
145149
});
146150
});

src/Views/InteractiveRebase.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
Background="{DynamicResource Brush.Contents}"
5858
ItemsSource="{Binding Items}"
5959
SelectionMode="Single"
60-
SelectedItem="{Binding SelectedItem, Mode=OneWayToSource}"
60+
SelectedItem="{Binding SelectedItem, Mode=TwoWay}"
6161
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
6262
ScrollViewer.VerticalScrollBarVisibility="Auto"
6363
Grid.IsSharedSizeScope="True">

src/Views/InteractiveRebase.axaml.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Avalonia.Input;
66
using Avalonia.Interactivity;
77
using Avalonia.Media;
8+
using Avalonia.VisualTree;
89

910
namespace SourceGit.Views
1011
{
@@ -73,6 +74,14 @@ public InteractiveRebase()
7374
InitializeComponent();
7475
}
7576

77+
protected override void OnLoaded(RoutedEventArgs e)
78+
{
79+
base.OnLoaded(e);
80+
81+
var list = this.FindDescendantOfType<InteractiveRebaseListBox>();
82+
list?.Focus();
83+
}
84+
7685
private void CloseWindow(object _1, RoutedEventArgs _2)
7786
{
7887
Close();

0 commit comments

Comments
 (0)