Skip to content

Commit 5d37dcc

Browse files
committed
refactor: search hotkey (#2059)
- Change the hotkey of searching commit from `Ctrl+F/⌘+F` to `Ctrl+Shift+F/⌘+⇧+F` - When some list is focused, pressing `Ctrl+F/⌘+F` will auto focus the right searchbox(filterbox) of it Signed-off-by: leo <longshuang@msn.cn>
1 parent dd94da5 commit 5d37dcc

19 files changed

+139
-27
lines changed

src/Views/BranchTree.axaml.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,15 @@ public event EventHandler<RoutedEventArgs> RowsChanged
303303
remove { RemoveHandler(RowsChangedEvent, value); }
304304
}
305305

306+
public static readonly RoutedEvent<RoutedEventArgs> SearchRequestedEvent =
307+
RoutedEvent.Register<BranchTree, RoutedEventArgs>(nameof(SearchRequested), RoutingStrategies.Tunnel | RoutingStrategies.Bubble);
308+
309+
public event EventHandler<RoutedEventArgs> SearchRequested
310+
{
311+
add { AddHandler(SearchRequestedEvent, value); }
312+
remove { RemoveHandler(SearchRequestedEvent, value); }
313+
}
314+
306315
public BranchTree()
307316
{
308317
InitializeComponent();
@@ -566,6 +575,13 @@ private void OnTreeContextRequested(object _1, ContextRequestedEventArgs _2)
566575

567576
private void OnTreeKeyDown(object _, KeyEventArgs e)
568577
{
578+
if (e.Key == Key.F && e.KeyModifiers == (OperatingSystem.IsMacOS() ? KeyModifiers.Meta : KeyModifiers.Control))
579+
{
580+
RaiseEvent(new RoutedEventArgs(SearchRequestedEvent));
581+
e.Handled = true;
582+
return;
583+
}
584+
569585
if (e.Key is not (Key.Delete or Key.Back))
570586
return;
571587

src/Views/CommitChanges.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<!-- Search & Display Mode -->
1919
<Grid Grid.Row="0" ColumnDefinitions="*,Auto">
2020
<TextBox Grid.Column="0"
21+
x:Name="CommitChangeSearchBox"
2122
Height="26"
2223
BorderThickness="1" BorderBrush="{DynamicResource Brush.Border2}"
2324
Background="Transparent"

src/Views/CommitChanges.axaml.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ private async void OnChangeCollectionViewKeyDown(object sender, KeyEventArgs e)
4242
if (sender is not ChangeCollectionView { SelectedChanges: { Count: > 0 } selectedChanges } view)
4343
return;
4444

45-
if (e.Key == Key.C &&
46-
e.KeyModifiers.HasFlag(OperatingSystem.IsMacOS() ? KeyModifiers.Meta : KeyModifiers.Control))
45+
var cmdKey = OperatingSystem.IsMacOS() ? KeyModifiers.Meta : KeyModifiers.Control;
46+
if (e.Key == Key.C && e.KeyModifiers.HasFlag(cmdKey))
4747
{
4848
var builder = new StringBuilder();
4949
var copyAbsPath = e.KeyModifiers.HasFlag(KeyModifiers.Shift);
@@ -65,6 +65,11 @@ private async void OnChangeCollectionViewKeyDown(object sender, KeyEventArgs e)
6565
await App.CopyTextAsync(builder.ToString());
6666
e.Handled = true;
6767
}
68+
else if (e.Key == Key.F && e.KeyModifiers == cmdKey)
69+
{
70+
CommitChangeSearchBox.Focus();
71+
e.Handled = true;
72+
}
6873
}
6974
}
7075
}

src/Views/Compare.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
<!-- Search & Display Mode -->
104104
<Grid Grid.Row="0" ColumnDefinitions="*,18">
105105
<TextBox Grid.Column="0"
106+
x:Name="ChangeSearchBox"
106107
Height="26"
107108
BorderThickness="1" BorderBrush="{DynamicResource Brush.Border2}"
108109
Background="Transparent"

src/Views/Compare.axaml.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@ private async void OnChangeCollectionViewKeyDown(object sender, KeyEventArgs e)
218218
if (sender is not ChangeCollectionView { SelectedChanges: { Count: > 0 } selectedChanges })
219219
return;
220220

221-
if (e.KeyModifiers.HasFlag(OperatingSystem.IsMacOS() ? KeyModifiers.Meta : KeyModifiers.Control) && e.Key == Key.C)
221+
var cmdKey = OperatingSystem.IsMacOS() ? KeyModifiers.Meta : KeyModifiers.Control;
222+
if (e.Key == Key.C && e.KeyModifiers.HasFlag(cmdKey))
222223
{
223224
var builder = new StringBuilder();
224225
var copyAbsPath = e.KeyModifiers.HasFlag(KeyModifiers.Shift);
@@ -235,6 +236,11 @@ private async void OnChangeCollectionViewKeyDown(object sender, KeyEventArgs e)
235236
await App.CopyTextAsync(builder.ToString());
236237
e.Handled = true;
237238
}
239+
else if (e.Key == Key.F && e.KeyModifiers == cmdKey)
240+
{
241+
ChangeSearchBox.Focus();
242+
e.Handled = true;
243+
}
238244
}
239245
}
240246
}

src/Views/Hotkeys.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
<TextBlock Grid.Row="0" Grid.Column="0" Classes="bold" Text="{OnPlatform Ctrl+Shift+H, macOS=⌘+⇧+H}"/>
8888
<TextBlock Grid.Row="0" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Repo.GoHome}" />
8989

90-
<TextBlock Grid.Row="1" Grid.Column="0" Classes="bold" Text="{OnPlatform Ctrl+F, macOS=⌘+F}"/>
90+
<TextBlock Grid.Row="1" Grid.Column="0" Classes="bold" Text="{OnPlatform Ctrl+Shift+F, macOS=⌘+⇧+F}"/>
9191
<TextBlock Grid.Row="1" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Repo.OpenSearchCommits}" />
9292

9393
<TextBlock Grid.Row="2" Grid.Column="0" Classes="bold" Text="{OnPlatform Ctrl+1, macOS=⌘+1}"/>

src/Views/Launcher.axaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ protected override async void OnKeyDown(KeyEventArgs e)
235235
repo.SelectedViewIndex = 2;
236236
e.Handled = true;
237237
return;
238-
case Key.F:
238+
case Key.F when e.KeyModifiers.HasFlag(KeyModifiers.Shift):
239239
repo.IsSearchingCommits = true;
240240
e.Handled = true;
241241
return;

src/Views/Repository.axaml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
<TextBlock>
4343
<Run Text="{DynamicResource Text.Repository.Search}" Foreground="{DynamicResource Brush.FG1}"/>
4444
<Run Text=" "/>
45-
<Run Text="{OnPlatform Ctrl+F, macOS=⌘+F}" FontSize="11" Foreground="{DynamicResource MenuFlyoutItemKeyboardAcceleratorTextForeground}"/>
45+
<Run Text="{OnPlatform Ctrl+Shift+F, macOS=⌘+⇧+F}" FontSize="11" Foreground="{DynamicResource MenuFlyoutItemKeyboardAcceleratorTextForeground}"/>
4646
</TextBlock>
4747
</ToolTip.Tip>
4848
<Path Width="12" Height="12" Stretch="Fill" HorizontalAlignment="Center" Data="{StaticResource Icons.Search}"/>
@@ -191,6 +191,7 @@
191191

192192
<!-- Filter Branches/Tags/Submodules -->
193193
<TextBox Grid.Row="1"
194+
x:Name="FilterBox"
194195
Height="26"
195196
Margin="8,6,4,0"
196197
BorderThickness="1"
@@ -253,7 +254,8 @@
253254
Nodes="{Binding LocalBranchTrees}"
254255
IsVisible="{Binding IsLocalBranchGroupExpanded}"
255256
SelectionChanged="OnLocalBranchTreeSelectionChanged"
256-
RowsChanged="OnLeftSidebarRowsChanged"/>
257+
RowsChanged="OnLeftSidebarRowsChanged"
258+
SearchRequested="OnToggleFilter"/>
257259

258260
<!-- Remotes -->
259261
<ToggleButton Grid.Row="2" Classes="group_expander" IsChecked="{Binding IsRemoteGroupExpanded, Mode=TwoWay}">
@@ -286,7 +288,8 @@
286288
Nodes="{Binding RemoteBranchTrees}"
287289
IsVisible="{Binding IsRemoteGroupExpanded}"
288290
SelectionChanged="OnRemoteBranchTreeSelectionChanged"
289-
RowsChanged="OnLeftSidebarRowsChanged"/>
291+
RowsChanged="OnLeftSidebarRowsChanged"
292+
SearchRequested="OnToggleFilter"/>
290293

291294
<!-- Tags -->
292295
<ToggleButton Grid.Row="4" Classes="group_expander" IsChecked="{Binding IsTagGroupExpanded, Mode=TwoWay}">
@@ -331,7 +334,8 @@
331334
Focusable="False"
332335
IsVisible="{Binding IsTagGroupExpanded, Mode=OneWay}"
333336
SelectionChanged="OnTagsSelectionChanged"
334-
RowsChanged="OnLeftSidebarRowsChanged"/>
337+
RowsChanged="OnLeftSidebarRowsChanged"
338+
SearchRequested="OnToggleFilter"/>
335339

336340
<!-- Submodules -->
337341
<ToggleButton Grid.Row="6" Classes="group_expander" IsChecked="{Binding IsSubmoduleGroupExpanded, Mode=TwoWay}">
@@ -373,7 +377,8 @@
373377
Content="{Binding VisibleSubmodules}"
374378
RowsChanged="OnLeftSidebarRowsChanged"
375379
Focusable="False"
376-
IsVisible="{Binding IsSubmoduleGroupExpanded, Mode=OneWay}"/>
380+
IsVisible="{Binding IsSubmoduleGroupExpanded, Mode=OneWay}"
381+
SearchRequested="OnToggleFilter"/>
377382

378383
<!-- Worktrees -->
379384
<ToggleButton Grid.Row="8" Classes="group_expander" IsChecked="{Binding IsWorktreeGroupExpanded, Mode=TwoWay}">

src/Views/Repository.axaml.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ protected override void OnLoaded(RoutedEventArgs e)
2020
UpdateLeftSidebarLayout();
2121
}
2222

23+
private void OnToggleFilter(object _, RoutedEventArgs e)
24+
{
25+
FilterBox.Focus();
26+
e.Handled = true;
27+
}
28+
2329
private void OnSearchCommitPanelPropertyChanged(object sender, AvaloniaPropertyChangedEventArgs e)
2430
{
2531
if (e.Property == IsVisibleProperty && sender is Grid { IsVisible: true })

src/Views/RevisionCompare.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
<!-- Search & Display Mode -->
7070
<Grid Grid.Row="0" ColumnDefinitions="*,18">
7171
<TextBox Grid.Column="0"
72+
x:Name="RevisionCompareChangeSearchBox"
7273
Height="26"
7374
BorderThickness="1" BorderBrush="{DynamicResource Brush.Border2}"
7475
Background="Transparent"

0 commit comments

Comments
 (0)