mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Add FocusQueryTextBox method to set focus on the query text box in MainWindow
This commit is contained in:
parent
ac614696b1
commit
edae432852
3 changed files with 23 additions and 2 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -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}");
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue