Clear Focus after 500ms user no input hotkey

This commit is contained in:
Kevin Zhang 2021-12-03 15:10:25 -06:00
parent 1f5478d3c5
commit c8a9c29463

View file

@ -28,7 +28,7 @@ namespace Flow.Launcher
private CancellationTokenSource hotkeyUpdateSource; private CancellationTokenSource hotkeyUpdateSource;
void TbHotkey_OnPreviewKeyDown(object sender, KeyEventArgs e) private void TbHotkey_OnPreviewKeyDown(object sender, KeyEventArgs e)
{ {
hotkeyUpdateSource?.Cancel(); hotkeyUpdateSource?.Cancel();
hotkeyUpdateSource?.Dispose(); hotkeyUpdateSource?.Dispose();
@ -56,15 +56,15 @@ namespace Flow.Launcher
return; return;
} }
Dispatcher.InvokeAsync(async () => _ = Dispatcher.InvokeAsync(async () =>
{ {
await Task.Delay(500); await Task.Delay(500, token);
if (!token.IsCancellationRequested) if (!token.IsCancellationRequested)
SetHotkey(hotkeyModel); await SetHotkey(hotkeyModel);
}); });
} }
public void SetHotkey(HotkeyModel keyModel, bool triggerValidate = true) public async Task SetHotkey(HotkeyModel keyModel, bool triggerValidate = true)
{ {
CurrentHotkey = keyModel; CurrentHotkey = keyModel;
@ -86,6 +86,13 @@ namespace Flow.Launcher
} }
tbMsg.Visibility = Visibility.Visible; tbMsg.Visibility = Visibility.Visible;
OnHotkeyChanged(); OnHotkeyChanged();
var token = hotkeyUpdateSource.Token;
await Task.Delay(500, token);
if (token.IsCancellationRequested)
return;
FocusManager.SetFocusedElement(FocusManager.GetFocusScope(this), null);
Keyboard.ClearFocus();
} }
} }