Skip to content

Commit d7a7d9b

Browse files
Maintain focus when hotkey invalid
1 parent 3f6ab55 commit d7a7d9b

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

Flow.Launcher/HotkeyControl.xaml.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,23 +63,35 @@ private void TbHotkey_OnPreviewKeyDown(object sender, KeyEventArgs e)
6363

6464
public async Task SetHotkeyAsync(HotkeyModel keyModel, bool triggerValidate = true)
6565
{
66-
CurrentHotkey = keyModel;
67-
68-
tbHotkey.Text = CurrentHotkey.ToString();
66+
tbHotkey.Text = keyModel.ToString();
6967
tbHotkey.Select(tbHotkey.Text.Length, 0);
7068

7169
if (triggerValidate)
7270
{
7371
bool hotkeyAvailable = CheckHotkeyAvailability(keyModel);
72+
CurrentHotkeyAvailable = hotkeyAvailable;
7473
SetMessage(hotkeyAvailable);
7574
OnHotkeyChanged();
7675

7776
var token = hotkeyUpdateSource.Token;
7877
await Task.Delay(500, token);
7978
if (token.IsCancellationRequested)
8079
return;
80+
81+
if (CurrentHotkeyAvailable)
82+
{
83+
CurrentHotkey = keyModel;
84+
}
85+
// triggers lost focus
8186
FocusManager.SetFocusedElement(FocusManager.GetFocusScope(this), null);
82-
Keyboard.ClearFocus();
87+
if (CurrentHotkeyAvailable)
88+
{
89+
Keyboard.ClearFocus();
90+
}
91+
}
92+
else
93+
{
94+
CurrentHotkey = keyModel;
8395
}
8496
}
8597

0 commit comments

Comments
 (0)