88using Flow . Launcher . Helper ;
99using Flow . Launcher . Infrastructure . Hotkey ;
1010using Flow . Launcher . Plugin ;
11+ using System . Threading ;
1112
1213namespace Flow . Launcher
1314{
@@ -25,8 +26,14 @@ public HotkeyControl()
2526 InitializeComponent ( ) ;
2627 }
2728
29+ private CancellationTokenSource hotkeyUpdateSource ;
30+
2831 void TbHotkey_OnPreviewKeyDown ( object sender , KeyEventArgs e )
2932 {
33+ hotkeyUpdateSource ? . Cancel ( ) ;
34+ hotkeyUpdateSource ? . Dispose ( ) ;
35+ hotkeyUpdateSource = new ( ) ;
36+ var token = hotkeyUpdateSource . Token ;
3037 e . Handled = true ;
3138 tbMsg . Visibility = Visibility . Hidden ;
3239
@@ -52,7 +59,8 @@ void TbHotkey_OnPreviewKeyDown(object sender, KeyEventArgs e)
5259 Dispatcher . InvokeAsync ( async ( ) =>
5360 {
5461 await Task . Delay ( 500 ) ;
55- SetHotkey ( hotkeyModel ) ;
62+ if ( ! token . IsCancellationRequested )
63+ SetHotkey ( hotkeyModel ) ;
5664 } ) ;
5765 }
5866
@@ -78,7 +86,6 @@ public void SetHotkey(HotkeyModel keyModel, bool triggerValidate = true)
7886 }
7987 tbMsg . Visibility = Visibility . Visible ;
8088 OnHotkeyChanged ( ) ;
81- Keyboard . ClearFocus ( ) ;
8289 }
8390 }
8491
@@ -89,9 +96,6 @@ public void SetHotkey(string keyStr, bool triggerValidate = true)
8996
9097 private bool CheckHotkeyAvailability ( ) => HotKeyMapper . CheckAvailability ( CurrentHotkey ) ;
9198
92- public new bool IsFocused
93- {
94- get { return tbHotkey . IsFocused ; }
95- }
99+ public new bool IsFocused => tbHotkey . IsFocused ;
96100 }
97- }
101+ }
0 commit comments