Add FocusQueryTextBox method to set focus on the query text box in MainWindow

This commit is contained in:
DB p 2025-05-22 04:14:30 +09:00
parent ac614696b1
commit edae432852
3 changed files with 23 additions and 2 deletions

View file

@ -88,6 +88,11 @@ namespace Flow.Launcher.Plugin
/// Show the MainWindow when hiding
/// </summary>
void ShowMainWindow();
/// <summary>
/// Focus the query text box in the main window
/// </summary>
void FocusQueryTextBox();
/// <summary>
/// Hide MainWindow

View file

@ -33,6 +33,7 @@ using JetBrains.Annotations;
using Squirrel;
using Stopwatch = Flow.Launcher.Infrastructure.Stopwatch;
using System.ComponentModel;
using System.Windows.Input;
namespace Flow.Launcher
{
@ -92,6 +93,18 @@ namespace Flow.Launcher
}
public void ShowMainWindow() => _mainVM.Show();
public void FocusQueryTextBox()
{
Application.Current.Dispatcher.Invoke(new Action(() =>
{
if (Application.Current.MainWindow is MainWindow mw)
{
mw.QueryTextBox.Focus();
Keyboard.Focus(mw.QueryTextBox);
}
}));
}
public void HideMainWindow() => _mainVM.Hide();

View file

@ -378,10 +378,13 @@ namespace Flow.Launcher.Plugin.Shell
private void OnWinRPressed()
{
Context.API.ShowMainWindow();
// show the main window and set focus to the query box
_ = Task.Run(() =>
_ = Task.Run(async () =>
{
Context.API.ShowMainWindow();
await Task.Delay(50); // 💡 키보드 이벤트 처리가 끝난 뒤
Context.API.FocusQueryTextBox();
Context.API.ChangeQuery($"{Context.CurrentPluginMetadata.ActionKeywords[0]}{Plugin.Query.TermSeparator}");
});
}