Skip to content

Commit c8a9c29

Browse files
committed
Clear Focus after 500ms user no input hotkey
1 parent 1f5478d commit c8a9c29

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

Flow.Launcher/HotkeyControl.xaml.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public HotkeyControl()
2828

2929
private CancellationTokenSource hotkeyUpdateSource;
3030

31-
void TbHotkey_OnPreviewKeyDown(object sender, KeyEventArgs e)
31+
private void TbHotkey_OnPreviewKeyDown(object sender, KeyEventArgs e)
3232
{
3333
hotkeyUpdateSource?.Cancel();
3434
hotkeyUpdateSource?.Dispose();
@@ -56,15 +56,15 @@ void TbHotkey_OnPreviewKeyDown(object sender, KeyEventArgs e)
5656
return;
5757
}
5858

59-
Dispatcher.InvokeAsync(async () =>
59+
_ = Dispatcher.InvokeAsync(async () =>
6060
{
61-
await Task.Delay(500);
61+
await Task.Delay(500, token);
6262
if (!token.IsCancellationRequested)
63-
SetHotkey(hotkeyModel);
63+
await SetHotkey(hotkeyModel);
6464
});
6565
}
6666

67-
public void SetHotkey(HotkeyModel keyModel, bool triggerValidate = true)
67+
public async Task SetHotkey(HotkeyModel keyModel, bool triggerValidate = true)
6868
{
6969
CurrentHotkey = keyModel;
7070

@@ -86,6 +86,13 @@ public void SetHotkey(HotkeyModel keyModel, bool triggerValidate = true)
8686
}
8787
tbMsg.Visibility = Visibility.Visible;
8888
OnHotkeyChanged();
89+
90+
var token = hotkeyUpdateSource.Token;
91+
await Task.Delay(500, token);
92+
if (token.IsCancellationRequested)
93+
return;
94+
FocusManager.SetFocusedElement(FocusManager.GetFocusScope(this), null);
95+
Keyboard.ClearFocus();
8996
}
9097
}
9198

0 commit comments

Comments
 (0)