Skip to content

Commit

Permalink
Don't snap on input nor dismiss selection for just a modifier key (#6431
Browse files Browse the repository at this point in the history
)

Does what it says on the label. Pure modifier keys weren't making it
this far at all prior to #6309. This PR changes these methods to make
sure that we only dismiss a selection or snap on input when the key
pressed isn't a modifier key.

## References

* regressed in #6309

## PR Checklist
* [x] Closes #6423
* [x] I work here
* [ ] Tests added/passed
* [n/a] Requires documentation to be updated

## Validation Steps Performed

* Tried to repro this in the Terminal, couldn't anymore.
  • Loading branch information
zadjii-msft authored Jun 9, 2020
1 parent f9b1238 commit e03e46b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .github/actions/spell-check/dictionary/apis.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ IMap
IObject
IStorage
LCID
LSHIFT
NCHITTEST
NCLBUTTONDBLCLK
NCRBUTTONDBLCLK
Expand All @@ -26,5 +27,6 @@ oaidl
ocidl
rfind
roundf
RSHIFT
SIZENS
tmp
5 changes: 4 additions & 1 deletion src/cascadia/TerminalControl/TermControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,10 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
// When there is a selection active, escape should clear it and NOT flow through
// to the terminal. With any other keypress, it should clear the selection AND
// flow through to the terminal.
if (_terminal->IsSelectionActive())
// GH#6423 - don't dismiss selection if the key that was pressed was a
// modifier key. We'll wait for a real keystroke to dismiss the
// selection.
if (_terminal->IsSelectionActive() && !KeyEvent::IsModifierKey(vkey))
{
_terminal->ClearSelection();
_renderer->TriggerSelection();
Expand Down
8 changes: 7 additions & 1 deletion src/cascadia/TerminalCore/Terminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,13 @@ bool Terminal::SendKeyEvent(const WORD vkey,
const ControlKeyStates states,
const bool keyDown)
{
TrySnapOnInput();
// GH#6423 - don't snap on this key if the key that was pressed was a
// modifier key. We'll wait for a real keystroke to snap to the bottom.
if (!KeyEvent::IsModifierKey(vkey))
{
TrySnapOnInput();
}

_StoreKeyEvent(vkey, scanCode);

const auto isAltOnlyPressed = states.IsAltPressed() && !states.IsCtrlPressed();
Expand Down
23 changes: 23 additions & 0 deletions src/types/inc/IInputEvent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,29 @@ class KeyEvent : public IInputEvent
bool IsCommandLineEditingKey() const noexcept;
bool IsPopupKey() const noexcept;

// Function Description:
// - Returns true if the given VKey represents a modifier key - shift, alt,
// control or the Win key.
// Arguments:
// - vkey: the VKEY to check
// Return Value:
// - true iff the key is a modifier key.
constexpr static bool IsModifierKey(const WORD vkey)
{
return (vkey == VK_CONTROL) ||
(vkey == VK_LCONTROL) ||
(vkey == VK_RCONTROL) ||
(vkey == VK_MENU) ||
(vkey == VK_LMENU) ||
(vkey == VK_RMENU) ||
(vkey == VK_SHIFT) ||
(vkey == VK_LSHIFT) ||
(vkey == VK_RSHIFT) ||
// There is no VK_WIN
(vkey == VK_LWIN) ||
(vkey == VK_RWIN);
};

private:
bool _keyDown;
WORD _repeatCount;
Expand Down

0 comments on commit e03e46b

Please sign in to comment.