Skip to content

Commit e78815e

Browse files
committed
enhance: block other hotkeys when there is a command palette (#2173
Signed-off-by: leo <longshuang@msn.cn>
1 parent 2f06b9e commit e78815e

File tree

5 files changed

+55
-7
lines changed

5 files changed

+55
-7
lines changed

src/Views/Launcher.axaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,9 @@
127127
<Border Grid.Row="0" Grid.RowSpan="2"
128128
Background="Transparent"
129129
IsVisible="{Binding CommandPalette, Converter={x:Static ObjectConverters.IsNotNull}}"
130-
PointerPressed="OnCloseCommandPalette">
130+
PointerPressed="OnCloseCommandPalette"
131+
KeyDown="OnCommandPaletteKeyDown"
132+
KeyUp="OnCommandPaletteKeyUp">
131133
<Border Width="420" HorizontalAlignment="Center" VerticalAlignment="Center" Effect="drop-shadow(0 0 12 #A0000000)">
132134
<Border Background="{DynamicResource Brush.Popup}" CornerRadius="8">
133135
<ContentControl Margin="16,10,16,12" Content="{Binding CommandPalette}">

src/Views/Launcher.axaml.cs

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
131131

132132
ViewModels.Preferences.Instance.Layout.LauncherWindowState = state;
133133
}
134+
else if (change.Property == IsActiveProperty)
135+
{
136+
if (!IsActive && DataContext is ViewModels.Launcher { CommandPalette: { } } vm)
137+
vm.CommandPalette = null;
138+
}
134139
}
135140

136141
protected override void OnSizeChanged(SizeChangedEventArgs e)
@@ -203,6 +208,13 @@ protected override async void OnKeyDown(KeyEventArgs e)
203208
return;
204209
}
205210

211+
if (e.Key == Key.T)
212+
{
213+
vm.AddNewTab();
214+
e.Handled = true;
215+
return;
216+
}
217+
206218
if ((OperatingSystem.IsMacOS() && e.KeyModifiers.HasFlag(KeyModifiers.Alt) && e.Key == Key.Right) ||
207219
(!OperatingSystem.IsMacOS() && !e.KeyModifiers.HasFlag(KeyModifiers.Shift) && e.Key == Key.Tab))
208220
{
@@ -265,11 +277,7 @@ protected override async void OnKeyDown(KeyEventArgs e)
265277
}
266278
else if (e.Key == Key.Escape)
267279
{
268-
if (vm.CommandPalette != null)
269-
vm.CommandPalette = null;
270-
else
271-
vm.ActivePage.CancelPopup();
272-
280+
vm.ActivePage.CancelPopup();
273281
e.Handled = true;
274282
return;
275283
}
@@ -317,6 +325,9 @@ private void OnOpenWorkspaceMenu(object sender, RoutedEventArgs e)
317325
{
318326
if (sender is Button btn && DataContext is ViewModels.Launcher launcher)
319327
{
328+
if (launcher.CommandPalette != null)
329+
launcher.CommandPalette = null;
330+
320331
var pref = ViewModels.Preferences.Instance;
321332
var menu = new ContextMenu();
322333
menu.Placement = PlacementMode.BottomEdgeAlignedLeft;
@@ -384,6 +395,23 @@ private void OnCloseCommandPalette(object sender, PointerPressedEventArgs e)
384395
e.Handled = true;
385396
}
386397

398+
private void OnCommandPaletteKeyDown(object sender, KeyEventArgs e)
399+
{
400+
if (DataContext is ViewModels.Launcher { CommandPalette: { } } vm)
401+
{
402+
if (e.Key == Key.Escape)
403+
vm.CommandPalette = null;
404+
405+
e.Route = RoutingStrategies.Direct;
406+
e.Handled = true;
407+
}
408+
}
409+
410+
private void OnCommandPaletteKeyUp(object sender, KeyEventArgs e)
411+
{
412+
e.Handled = true;
413+
}
414+
387415
private WindowState _lastWindowState = WindowState.Normal;
388416
}
389417
}

src/Views/LauncherTabBar.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@
153153
<Path Width="8" Height="14" Stretch="Fill" Data="{StaticResource Icons.TriangleRight}"/>
154154
</RepeatButton>
155155

156-
<Button Classes="icon_button" Width="16" Height="28" Margin="4,2,0,0" Command="{Binding AddNewTab}" HotKey="{OnPlatform Ctrl+T, macOS=⌘+T}">
156+
<Button Classes="icon_button" Width="16" Height="28" Margin="4,2,0,0" Command="{Binding AddNewTab}">
157157
<ToolTip.Tip>
158158
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
159159
<TextBlock Text="{DynamicResource Text.PageTabBar.New}" VerticalAlignment="Center"/>

src/Views/RepositoryToolbar.axaml.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ private async void Fetch(object sender, TappedEventArgs e)
163163

164164
private async void FetchDirectlyByHotKey(object sender, RoutedEventArgs e)
165165
{
166+
if (App.GetLauncher() is { CommandPalette: { } } launcher)
167+
return;
168+
166169
if (DataContext is ViewModels.Repository repo)
167170
{
168171
await repo.FetchAsync(true);
@@ -181,6 +184,9 @@ private async void Pull(object sender, TappedEventArgs e)
181184

182185
private async void PullDirectlyByHotKey(object sender, RoutedEventArgs e)
183186
{
187+
if (App.GetLauncher() is { CommandPalette: { } } launcher)
188+
return;
189+
184190
if (DataContext is ViewModels.Repository repo)
185191
{
186192
await repo.PullAsync(true);
@@ -199,6 +205,9 @@ private async void Push(object sender, TappedEventArgs e)
199205

200206
private async void PushDirectlyByHotKey(object sender, RoutedEventArgs e)
201207
{
208+
if (App.GetLauncher() is { CommandPalette: { } } launcher)
209+
return;
210+
202211
if (DataContext is ViewModels.Repository repo)
203212
{
204213
await repo.PushAsync(true);

src/Views/WorkingCopy.axaml.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,9 @@ private async void OnContinue(object _, RoutedEventArgs e)
231231

232232
private async void OnCommit(object _, RoutedEventArgs e)
233233
{
234+
if (App.GetLauncher() is { CommandPalette: { } } launcher)
235+
return;
236+
234237
if (DataContext is ViewModels.WorkingCopy vm)
235238
await vm.CommitAsync(false, false);
236239

@@ -239,6 +242,9 @@ private async void OnCommit(object _, RoutedEventArgs e)
239242

240243
private async void OnCommitWithAutoStage(object _, RoutedEventArgs e)
241244
{
245+
if (App.GetLauncher() is { CommandPalette: { } } launcher)
246+
return;
247+
242248
if (DataContext is ViewModels.WorkingCopy vm)
243249
await vm.CommitAsync(true, false);
244250

@@ -247,6 +253,9 @@ private async void OnCommitWithAutoStage(object _, RoutedEventArgs e)
247253

248254
private async void OnCommitWithPush(object _, RoutedEventArgs e)
249255
{
256+
if (App.GetLauncher() is { CommandPalette: { } } launcher)
257+
return;
258+
250259
if (DataContext is ViewModels.WorkingCopy vm)
251260
await vm.CommitAsync(false, true);
252261

0 commit comments

Comments
 (0)