Skip to content

Commit edae432

Browse files
committed
Add FocusQueryTextBox method to set focus on the query text box in MainWindow
1 parent ac61469 commit edae432

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ public interface IPublicAPI
8888
/// Show the MainWindow when hiding
8989
/// </summary>
9090
void ShowMainWindow();
91+
92+
/// <summary>
93+
/// Focus the query text box in the main window
94+
/// </summary>
95+
void FocusQueryTextBox();
9196

9297
/// <summary>
9398
/// Hide MainWindow

Flow.Launcher/PublicAPIInstance.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
using Squirrel;
3434
using Stopwatch = Flow.Launcher.Infrastructure.Stopwatch;
3535
using System.ComponentModel;
36+
using System.Windows.Input;
3637

3738
namespace Flow.Launcher
3839
{
@@ -92,6 +93,18 @@ public async void RestartApp()
9293
}
9394

9495
public void ShowMainWindow() => _mainVM.Show();
96+
97+
public void FocusQueryTextBox()
98+
{
99+
Application.Current.Dispatcher.Invoke(new Action(() =>
100+
{
101+
if (Application.Current.MainWindow is MainWindow mw)
102+
{
103+
mw.QueryTextBox.Focus();
104+
Keyboard.Focus(mw.QueryTextBox);
105+
}
106+
}));
107+
}
95108

96109
public void HideMainWindow() => _mainVM.Hide();
97110

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,10 +378,13 @@ bool API_GlobalKeyboardEvent(int keyevent, int vkcode, SpecialKeyState state)
378378

379379
private void OnWinRPressed()
380380
{
381+
Context.API.ShowMainWindow();
381382
// show the main window and set focus to the query box
382-
_ = Task.Run(() =>
383+
_ = Task.Run(async () =>
383384
{
384-
Context.API.ShowMainWindow();
385+
await Task.Delay(50); // 💡 키보드 이벤트 처리가 끝난 뒤
386+
Context.API.FocusQueryTextBox();
387+
385388
Context.API.ChangeQuery($"{Context.CurrentPluginMetadata.ActionKeywords[0]}{Plugin.Query.TermSeparator}");
386389
});
387390
}

0 commit comments

Comments
 (0)