Skip to content

Commit a312fe8

Browse files
authored
Merge pull request #489 from lzl1918/lzl1918/FixShellPluginDoesNotAutoFocus
[Plugin.Shell] Fix: The Query Box Is Not Focused When HotKey Invoked
2 parents 4e28b52 + 867c2a7 commit a312fe8

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

Flow.Launcher/CustomQueryHotkeySetting.xaml.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ private void btnAdd_OnClick(object sender, RoutedEventArgs e)
5555
SetHotkey(ctlHotkey.CurrentHotkey, delegate
5656
{
5757
App.API.ChangeQuery(pluginHotkey.ActionKeyword);
58-
Application.Current.MainWindow.Visibility = Visibility.Visible;
58+
ShowMainWindow();
5959
});
6060
}
6161
else
@@ -73,11 +73,18 @@ private void btnAdd_OnClick(object sender, RoutedEventArgs e)
7373
SetHotkey(new HotkeyModel(updateCustomHotkey.Hotkey), delegate
7474
{
7575
App.API.ChangeQuery(updateCustomHotkey.ActionKeyword);
76-
Application.Current.MainWindow.Visibility = Visibility.Visible;
76+
ShowMainWindow();
7777
});
7878
}
7979

8080
Close();
81+
82+
static void ShowMainWindow()
83+
{
84+
Window mainWindow = Application.Current.MainWindow;
85+
mainWindow.Visibility = Visibility.Visible;
86+
mainWindow.Focus();
87+
}
8188
}
8289

8390
public void UpdateItem(CustomPluginHotkey item)

Plugins/Flow.Launcher.Plugin.Shell/Main.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,11 @@ bool API_GlobalKeyboardEvent(int keyevent, int vkcode, SpecialKeyState state)
298298
private void OnWinRPressed()
299299
{
300300
context.API.ChangeQuery($"{context.CurrentPluginMetadata.ActionKeywords[0]}{Plugin.Query.TermSeperater}");
301-
Application.Current.MainWindow.Visibility = Visibility.Visible;
301+
302+
// show the main window and set focus to the query box
303+
Window mainWindow = Application.Current.MainWindow;
304+
mainWindow.Visibility = Visibility.Visible;
305+
mainWindow.Focus();
302306
}
303307

304308
public Control CreateSettingPanel()

0 commit comments

Comments
 (0)