enhance: allow to use arrow keys to select changes up/down after stage/unstage previous selected changes by hotkey (#1361)
Some checks are pending
Continuous Integration / Build (push) Waiting to run
Continuous Integration / Prepare version string (push) Waiting to run
Continuous Integration / Package (push) Blocked by required conditions

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo 2025-05-24 21:29:48 +08:00
parent ef53dd0025
commit 22339ab619
No known key found for this signature in database
4 changed files with 20 additions and 11 deletions

View file

@ -30,7 +30,8 @@
<UserControl.DataTemplates> <UserControl.DataTemplates>
<DataTemplate DataType="vm:ChangeCollectionAsTree"> <DataTemplate DataType="vm:ChangeCollectionAsTree">
<v:ChangeCollectionContainer ItemsSource="{Binding Rows}" <v:ChangeCollectionContainer Focusable="True"
ItemsSource="{Binding Rows}"
SelectedItems="{Binding SelectedRows, Mode=TwoWay}" SelectedItems="{Binding SelectedRows, Mode=TwoWay}"
SelectionMode="{Binding #ThisControl.SelectionMode}" SelectionMode="{Binding #ThisControl.SelectionMode}"
SelectionChanged="OnRowSelectionChanged"> SelectionChanged="OnRowSelectionChanged">
@ -66,7 +67,8 @@
</DataTemplate> </DataTemplate>
<DataTemplate DataType="vm:ChangeCollectionAsGrid"> <DataTemplate DataType="vm:ChangeCollectionAsGrid">
<v:ChangeCollectionContainer ItemsSource="{Binding Changes}" <v:ChangeCollectionContainer Focusable="True"
ItemsSource="{Binding Changes}"
SelectedItems="{Binding SelectedChanges, Mode=TwoWay}" SelectedItems="{Binding SelectedChanges, Mode=TwoWay}"
SelectionMode="{Binding #ThisControl.SelectionMode}" SelectionMode="{Binding #ThisControl.SelectionMode}"
SelectionChanged="OnRowSelectionChanged"> SelectionChanged="OnRowSelectionChanged">
@ -98,7 +100,8 @@
</DataTemplate> </DataTemplate>
<DataTemplate DataType="vm:ChangeCollectionAsList"> <DataTemplate DataType="vm:ChangeCollectionAsList">
<v:ChangeCollectionContainer ItemsSource="{Binding Changes}" <v:ChangeCollectionContainer Focusable="True"
ItemsSource="{Binding Changes}"
SelectedItems="{Binding SelectedChanges, Mode=TwoWay}" SelectedItems="{Binding SelectedChanges, Mode=TwoWay}"
SelectionMode="{Binding #ThisControl.SelectionMode}" SelectionMode="{Binding #ThisControl.SelectionMode}"
SelectionChanged="OnRowSelectionChanged"> SelectionChanged="OnRowSelectionChanged">

View file

@ -145,6 +145,7 @@ namespace SourceGit.Views
removeCount++; removeCount++;
} }
tree.Rows.RemoveRange(idx + 1, removeCount); tree.Rows.RemoveRange(idx + 1, removeCount);
} }
} }
@ -209,6 +210,13 @@ namespace SourceGit.Views
return null; return null;
} }
public void TakeFocus()
{
var container = this.FindDescendantOfType<ChangeCollectionContainer>();
if (container is { IsFocused: false })
container.Focus();
}
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change) protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
{ {
base.OnPropertyChanged(change); base.OnPropertyChanged(change);

View file

@ -122,7 +122,6 @@
<!-- Unstaged Changes --> <!-- Unstaged Changes -->
<v:ChangeCollectionView Grid.Row="1" <v:ChangeCollectionView Grid.Row="1"
x:Name="UnstagedChangesView" x:Name="UnstagedChangesView"
Focusable="True"
IsUnstagedChange="True" IsUnstagedChange="True"
SelectionMode="Multiple" SelectionMode="Multiple"
Background="{DynamicResource Brush.Contents}" Background="{DynamicResource Brush.Contents}"
@ -173,7 +172,6 @@
<!-- Staged Changes --> <!-- Staged Changes -->
<v:ChangeCollectionView Grid.Row="1" <v:ChangeCollectionView Grid.Row="1"
x:Name="StagedChangesView" x:Name="StagedChangesView"
Focusable="True"
IsUnstagedChange="False" IsUnstagedChange="False"
SelectionMode="Multiple" SelectionMode="Multiple"
Background="{DynamicResource Brush.Contents}" Background="{DynamicResource Brush.Contents}"

View file

@ -51,7 +51,7 @@ namespace SourceGit.Views
{ {
var next = UnstagedChangesView.GetNextChangeWithoutSelection(); var next = UnstagedChangesView.GetNextChangeWithoutSelection();
vm.StageSelected(next); vm.StageSelected(next);
UnstagedChangesView.Focus(); UnstagedChangesView.TakeFocus();
e.Handled = true; e.Handled = true;
} }
} }
@ -62,7 +62,7 @@ namespace SourceGit.Views
{ {
var next = StagedChangesView.GetNextChangeWithoutSelection(); var next = StagedChangesView.GetNextChangeWithoutSelection();
vm.UnstageSelected(next); vm.UnstageSelected(next);
StagedChangesView.Focus(); StagedChangesView.TakeFocus();
e.Handled = true; e.Handled = true;
} }
} }
@ -75,7 +75,7 @@ namespace SourceGit.Views
{ {
var next = UnstagedChangesView.GetNextChangeWithoutSelection(); var next = UnstagedChangesView.GetNextChangeWithoutSelection();
vm.StageSelected(next); vm.StageSelected(next);
UnstagedChangesView.Focus(); UnstagedChangesView.TakeFocus();
e.Handled = true; e.Handled = true;
return; return;
} }
@ -94,7 +94,7 @@ namespace SourceGit.Views
{ {
var next = StagedChangesView.GetNextChangeWithoutSelection(); var next = StagedChangesView.GetNextChangeWithoutSelection();
vm.UnstageSelected(next); vm.UnstageSelected(next);
StagedChangesView.Focus(); StagedChangesView.TakeFocus();
e.Handled = true; e.Handled = true;
} }
} }
@ -105,7 +105,7 @@ namespace SourceGit.Views
{ {
var next = UnstagedChangesView.GetNextChangeWithoutSelection(); var next = UnstagedChangesView.GetNextChangeWithoutSelection();
vm.StageSelected(next); vm.StageSelected(next);
UnstagedChangesView.Focus(); UnstagedChangesView.TakeFocus();
} }
e.Handled = true; e.Handled = true;
@ -117,7 +117,7 @@ namespace SourceGit.Views
{ {
var next = StagedChangesView.GetNextChangeWithoutSelection(); var next = StagedChangesView.GetNextChangeWithoutSelection();
vm.UnstageSelected(next); vm.UnstageSelected(next);
StagedChangesView.Focus(); StagedChangesView.TakeFocus();
} }
e.Handled = true; e.Handled = true;