Do not dismiss selection if the Windows keys is pressed as a key-combination (#9163)

Aims to fix #8791.

<!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? -->
## Summary of the Pull Request
Prior to this PR, if the Windows key was pressed as a part of a key combination, then selection was being dismissed. For example,  when a user pressed `Windows` + `Shift` + `S` keys to invoke the _Capture & Annotate_ tool.
This PR adds an exception for not clearing selection when either of the two Windows keys are pressed as part of a key combination.
It was tested manually by trying to reproduce the issue.

<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist
* [ ] Closes #8791
* [x ] CLA signed.
* [x ] I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: #8791

<!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed
1. Build Terminal.
2. Write anything & make a selection.
3. Press `Windows`+ `Shift` + `S` keys.
4. The _Capture & Annotate_ tool appears but the selection made in step 2 isn't dismissed (doesn't disappear).
This commit is contained in:
SJ 2021-02-17 11:41:25 -06:00 committed by GitHub
parent 525be22bd8
commit 7d37ba22e7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1100,8 +1100,18 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
// selection.
if (_terminal->IsSelectionActive() && !KeyEvent::IsModifierKey(vkey) && vkey != VK_SNAPSHOT)
{
_terminal->ClearSelection();
_renderer->TriggerSelection();
const CoreWindow window = CoreWindow::GetForCurrentThread();
const auto leftWinKeyState = window.GetKeyState(VirtualKey::LeftWindows);
const auto rightWinKeyState = window.GetKeyState(VirtualKey::RightWindows);
const auto isLeftWinKeyDown = WI_IsFlagSet(leftWinKeyState, CoreVirtualKeyStates::Down);
const auto isRightWinKeyDown = WI_IsFlagSet(rightWinKeyState, CoreVirtualKeyStates::Down);
// GH#8791 - don't dismiss selection if Windows key was also pressed as a key-combination.
if (!isLeftWinKeyDown && !isRightWinKeyDown)
{
_terminal->ClearSelection();
_renderer->TriggerSelection();
}
if (vkey == VK_ESCAPE)
{
@ -2881,7 +2891,7 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
// - The Microsoft::Terminal::Core::ControlKeyStates representing the modifier key states.
ControlKeyStates TermControl::_GetPressedModifierKeys() const
{
CoreWindow window = CoreWindow::GetForCurrentThread();
const CoreWindow window = CoreWindow::GetForCurrentThread();
// DONT USE
// != CoreVirtualKeyStates::None
// OR