Skip to content

Commit 22339ab

Browse files
committed
enhance: allow to use arrow keys to select changes up/down after stage/unstage previous selected changes by hotkey (#1361)
Signed-off-by: leo <[email protected]>
1 parent ef53dd0 commit 22339ab

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

src/Views/ChangeCollectionView.axaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030

3131
<UserControl.DataTemplates>
3232
<DataTemplate DataType="vm:ChangeCollectionAsTree">
33-
<v:ChangeCollectionContainer ItemsSource="{Binding Rows}"
33+
<v:ChangeCollectionContainer Focusable="True"
34+
ItemsSource="{Binding Rows}"
3435
SelectedItems="{Binding SelectedRows, Mode=TwoWay}"
3536
SelectionMode="{Binding #ThisControl.SelectionMode}"
3637
SelectionChanged="OnRowSelectionChanged">
@@ -66,7 +67,8 @@
6667
</DataTemplate>
6768

6869
<DataTemplate DataType="vm:ChangeCollectionAsGrid">
69-
<v:ChangeCollectionContainer ItemsSource="{Binding Changes}"
70+
<v:ChangeCollectionContainer Focusable="True"
71+
ItemsSource="{Binding Changes}"
7072
SelectedItems="{Binding SelectedChanges, Mode=TwoWay}"
7173
SelectionMode="{Binding #ThisControl.SelectionMode}"
7274
SelectionChanged="OnRowSelectionChanged">
@@ -98,7 +100,8 @@
98100
</DataTemplate>
99101

100102
<DataTemplate DataType="vm:ChangeCollectionAsList">
101-
<v:ChangeCollectionContainer ItemsSource="{Binding Changes}"
103+
<v:ChangeCollectionContainer Focusable="True"
104+
ItemsSource="{Binding Changes}"
102105
SelectedItems="{Binding SelectedChanges, Mode=TwoWay}"
103106
SelectionMode="{Binding #ThisControl.SelectionMode}"
104107
SelectionChanged="OnRowSelectionChanged">

src/Views/ChangeCollectionView.axaml.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ public void ToggleNodeIsExpanded(ViewModels.ChangeTreeNode node)
145145

146146
removeCount++;
147147
}
148+
148149
tree.Rows.RemoveRange(idx + 1, removeCount);
149150
}
150151
}
@@ -209,6 +210,13 @@ public Models.Change GetNextChangeWithoutSelection()
209210
return null;
210211
}
211212

213+
public void TakeFocus()
214+
{
215+
var container = this.FindDescendantOfType<ChangeCollectionContainer>();
216+
if (container is { IsFocused: false })
217+
container.Focus();
218+
}
219+
212220
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
213221
{
214222
base.OnPropertyChanged(change);

src/Views/WorkingCopy.axaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@
122122
<!-- Unstaged Changes -->
123123
<v:ChangeCollectionView Grid.Row="1"
124124
x:Name="UnstagedChangesView"
125-
Focusable="True"
126125
IsUnstagedChange="True"
127126
SelectionMode="Multiple"
128127
Background="{DynamicResource Brush.Contents}"
@@ -173,7 +172,6 @@
173172
<!-- Staged Changes -->
174173
<v:ChangeCollectionView Grid.Row="1"
175174
x:Name="StagedChangesView"
176-
Focusable="True"
177175
IsUnstagedChange="False"
178176
SelectionMode="Multiple"
179177
Background="{DynamicResource Brush.Contents}"

src/Views/WorkingCopy.axaml.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ private void OnUnstagedChangeDoubleTapped(object _, RoutedEventArgs e)
5151
{
5252
var next = UnstagedChangesView.GetNextChangeWithoutSelection();
5353
vm.StageSelected(next);
54-
UnstagedChangesView.Focus();
54+
UnstagedChangesView.TakeFocus();
5555
e.Handled = true;
5656
}
5757
}
@@ -62,7 +62,7 @@ private void OnStagedChangeDoubleTapped(object _, RoutedEventArgs e)
6262
{
6363
var next = StagedChangesView.GetNextChangeWithoutSelection();
6464
vm.UnstageSelected(next);
65-
StagedChangesView.Focus();
65+
StagedChangesView.TakeFocus();
6666
e.Handled = true;
6767
}
6868
}
@@ -75,7 +75,7 @@ private void OnUnstagedKeyDown(object _, KeyEventArgs e)
7575
{
7676
var next = UnstagedChangesView.GetNextChangeWithoutSelection();
7777
vm.StageSelected(next);
78-
UnstagedChangesView.Focus();
78+
UnstagedChangesView.TakeFocus();
7979
e.Handled = true;
8080
return;
8181
}
@@ -94,7 +94,7 @@ private void OnStagedKeyDown(object _, KeyEventArgs e)
9494
{
9595
var next = StagedChangesView.GetNextChangeWithoutSelection();
9696
vm.UnstageSelected(next);
97-
StagedChangesView.Focus();
97+
StagedChangesView.TakeFocus();
9898
e.Handled = true;
9999
}
100100
}
@@ -105,7 +105,7 @@ private void OnStageSelectedButtonClicked(object _, RoutedEventArgs e)
105105
{
106106
var next = UnstagedChangesView.GetNextChangeWithoutSelection();
107107
vm.StageSelected(next);
108-
UnstagedChangesView.Focus();
108+
UnstagedChangesView.TakeFocus();
109109
}
110110

111111
e.Handled = true;
@@ -117,7 +117,7 @@ private void OnUnstageSelectedButtonClicked(object _, RoutedEventArgs e)
117117
{
118118
var next = StagedChangesView.GetNextChangeWithoutSelection();
119119
vm.UnstageSelected(next);
120-
StagedChangesView.Focus();
120+
StagedChangesView.TakeFocus();
121121
}
122122

123123
e.Handled = true;

0 commit comments

Comments
 (0)