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

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

View file

@ -33,6 +33,7 @@ using JetBrains.Annotations;
using Squirrel; using Squirrel;
using Stopwatch = Flow.Launcher.Infrastructure.Stopwatch; using Stopwatch = Flow.Launcher.Infrastructure.Stopwatch;
using System.ComponentModel; using System.ComponentModel;
using System.Windows.Input;
namespace Flow.Launcher namespace Flow.Launcher
{ {
@ -93,6 +94,18 @@ namespace Flow.Launcher
public void ShowMainWindow() => _mainVM.Show(); 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(); public void HideMainWindow() => _mainVM.Hide();
public bool IsMainWindowVisible() => _mainVM.MainWindowVisibilityStatus; public bool IsMainWindowVisible() => _mainVM.MainWindowVisibilityStatus;

View file

@ -378,10 +378,13 @@ namespace Flow.Launcher.Plugin.Shell
private void OnWinRPressed() private void OnWinRPressed()
{ {
Context.API.ShowMainWindow();
// show the main window and set focus to the query box // 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}"); Context.API.ChangeQuery($"{Context.CurrentPluginMetadata.ActionKeywords[0]}{Plugin.Query.TermSeparator}");
}); });
} }