Fix KeyChord constructor assertion failure during tab dragging (#11306)
For some weird reason we sometimes receive a WM_KEYDOWN message without vkey or scanCode if a user drags a tab. The KeyChord constructor has a debug assertion ensuring that all KeyChord either have a valid vkey/scanCode. This is important, because this prevents accidential insertion of invalid KeyChords into classes like ActionMap. ## PR Checklist * [x] Closes #11076 * [x] I work here * [x] Tests added/passed ## Validation Steps Performed * Tab dragging doesn't produce assertion failures anymore ✔️
This commit is contained in:
parent
3afcd575df
commit
86ba1fc6c3
|
@ -848,6 +848,23 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const auto keyStatus = e.KeyStatus();
|
||||||
|
const auto vkey = gsl::narrow_cast<WORD>(e.OriginalKey());
|
||||||
|
const auto scanCode = gsl::narrow_cast<WORD>(keyStatus.ScanCode);
|
||||||
|
auto modifiers = _GetPressedModifierKeys();
|
||||||
|
|
||||||
|
// GH#11076:
|
||||||
|
// For some weird reason we sometimes receive a WM_KEYDOWN
|
||||||
|
// message without vkey or scanCode if a user drags a tab.
|
||||||
|
// The KeyChord constructor has a debug assertion ensuring that all KeyChord
|
||||||
|
// either have a valid vkey/scanCode. This is important, because this prevents
|
||||||
|
// accidential insertion of invalid KeyChords into classes like ActionMap.
|
||||||
|
if (!vkey && !scanCode)
|
||||||
|
{
|
||||||
|
e.Handled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Mark the event as handled and do nothing if we're closing, or the key
|
// Mark the event as handled and do nothing if we're closing, or the key
|
||||||
// was the Windows key.
|
// was the Windows key.
|
||||||
//
|
//
|
||||||
|
@ -856,19 +873,12 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||||
// win32-input-mode, then we'll send all these keystrokes to the
|
// win32-input-mode, then we'll send all these keystrokes to the
|
||||||
// terminal - it's smart enough to ignore the keys it doesn't care
|
// terminal - it's smart enough to ignore the keys it doesn't care
|
||||||
// about.
|
// about.
|
||||||
if (_IsClosing() ||
|
if (_IsClosing() || vkey == VK_LWIN || vkey == VK_RWIN)
|
||||||
e.OriginalKey() == VirtualKey::LeftWindows ||
|
|
||||||
e.OriginalKey() == VirtualKey::RightWindows)
|
|
||||||
|
|
||||||
{
|
{
|
||||||
e.Handled(true);
|
e.Handled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto modifiers = _GetPressedModifierKeys();
|
|
||||||
const auto vkey = gsl::narrow_cast<WORD>(e.OriginalKey());
|
|
||||||
const auto scanCode = gsl::narrow_cast<WORD>(e.KeyStatus().ScanCode);
|
|
||||||
|
|
||||||
// Short-circuit isReadOnly check to avoid warning dialog
|
// Short-circuit isReadOnly check to avoid warning dialog
|
||||||
if (_core.IsInReadOnlyMode())
|
if (_core.IsInReadOnlyMode())
|
||||||
{
|
{
|
||||||
|
@ -876,7 +886,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e.KeyStatus().IsExtendedKey)
|
if (keyStatus.IsExtendedKey)
|
||||||
{
|
{
|
||||||
modifiers |= ControlKeyStates::EnhancedKey;
|
modifiers |= ControlKeyStates::EnhancedKey;
|
||||||
}
|
}
|
||||||
|
@ -886,8 +896,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||||
// will be sent through the TSFInputControl. See GH#1401 for more
|
// will be sent through the TSFInputControl. See GH#1401 for more
|
||||||
// details
|
// details
|
||||||
if (modifiers.IsAltPressed() &&
|
if (modifiers.IsAltPressed() &&
|
||||||
(e.OriginalKey() >= VirtualKey::NumberPad0 && e.OriginalKey() <= VirtualKey::NumberPad9))
|
(vkey >= VK_NUMPAD0 && vkey <= VK_NUMPAD9))
|
||||||
|
|
||||||
{
|
{
|
||||||
e.Handled(true);
|
e.Handled(true);
|
||||||
return;
|
return;
|
||||||
|
@ -917,7 +926,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||||
// Manually prevent keyboard navigation with tab. We want to send tab to
|
// Manually prevent keyboard navigation with tab. We want to send tab to
|
||||||
// the terminal, and we don't want to be able to escape focus of the
|
// the terminal, and we don't want to be able to escape focus of the
|
||||||
// control with tab.
|
// control with tab.
|
||||||
e.Handled(e.OriginalKey() == VirtualKey::Tab);
|
e.Handled(vkey == VK_TAB);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Method Description:
|
// Method Description:
|
||||||
|
|
Loading…
Reference in a new issue