File tree Expand file tree Collapse file tree 3 files changed +25
-17
lines changed
Plugins/Flow.Launcher.Plugin.Shell Expand file tree Collapse file tree 3 files changed +25
-17
lines changed Original file line number Diff line number Diff line change 2
2
using System . Collections . Concurrent ;
3
3
using System . Collections . Generic ;
4
4
using System . Collections . Specialized ;
5
+ using System . ComponentModel ;
5
6
using System . Diagnostics ;
6
7
using System . IO ;
7
8
using System . Linq ;
10
11
using System . Threading ;
11
12
using System . Threading . Tasks ;
12
13
using System . Windows ;
14
+ using System . Windows . Input ;
13
15
using System . Windows . Media ;
14
16
using CommunityToolkit . Mvvm . DependencyInjection ;
15
17
using Flow . Launcher . Core ;
32
34
using JetBrains . Annotations ;
33
35
using Squirrel ;
34
36
using Stopwatch = Flow . Launcher . Infrastructure . Stopwatch ;
35
- using System . ComponentModel ;
36
- using System . Windows . Input ;
37
37
38
38
namespace Flow . Launcher
39
39
{
@@ -93,18 +93,8 @@ public async void RestartApp()
93
93
}
94
94
95
95
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
- }
96
+
97
+ public void FocusQueryTextBox ( ) => _mainVM . FocusQueryTextBox ( ) ;
108
98
109
99
public void HideMainWindow ( ) => _mainVM . Hide ( ) ;
110
100
Original file line number Diff line number Diff line change @@ -1926,6 +1926,21 @@ public void UpdateResultView(ICollection<ResultsForUpdate> resultsForUpdates)
1926
1926
Results . AddResults ( resultsForUpdates , token , reSelect ) ;
1927
1927
}
1928
1928
1929
+ [ System . Diagnostics . CodeAnalysis . SuppressMessage ( "Performance" , "CA1822:Mark members as static" , Justification = "<Pending>" ) ]
1930
+ public void FocusQueryTextBox ( )
1931
+ {
1932
+ // When application is exiting, the Application.Current will be null
1933
+ Application . Current ? . Dispatcher . Invoke ( ( ) =>
1934
+ {
1935
+ // When application is exiting, the Application.Current will be null
1936
+ if ( Application . Current ? . MainWindow is MainWindow window )
1937
+ {
1938
+ window . QueryTextBox . Focus ( ) ;
1939
+ Keyboard . Focus ( window . QueryTextBox ) ;
1940
+ }
1941
+ } ) ;
1942
+ }
1943
+
1929
1944
#endregion
1930
1945
1931
1946
#region IDisposable
Original file line number Diff line number Diff line change @@ -382,10 +382,13 @@ private void OnWinRPressed()
382
382
// show the main window and set focus to the query box
383
383
_ = Task . Run ( async ( ) =>
384
384
{
385
- await Task . Delay ( 50 ) ; // 💡 키보드 이벤트 처리가 끝난 뒤
386
- Context . API . FocusQueryTextBox ( ) ;
387
-
388
385
Context . API . ChangeQuery ( $ "{ Context . CurrentPluginMetadata . ActionKeywords [ 0 ] } { Plugin . Query . TermSeparator } ") ;
386
+
387
+ // Win+R is a system-reserved shortcut, and though the plugin intercepts the keyboard event and
388
+ // shows the main window, Windows continues to process the Win key and briefly reclaims focus.
389
+ // So we need to wait until the keyboard event processing is completed and then set focus
390
+ await Task . Delay ( 50 ) ;
391
+ Context . API . FocusQueryTextBox ( ) ;
389
392
} ) ;
390
393
}
391
394
You can’t perform that action at this time.
0 commit comments