From b00988d9c255a77c022959b2f055ab72ef811d6d Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Tue, 2 Nov 2021 14:40:30 -0500 Subject: [PATCH 1/3] I don't think I need the TerminalPage.xaml change here, but the TabBase one feels unnecessarily hacky. That being said, there's no non-hack solution to this one. --- src/cascadia/TerminalApp/TabBase.cpp | 20 ++++++++++++++++++++ src/cascadia/TerminalApp/TabBase.h | 3 +++ src/cascadia/TerminalApp/TerminalPage.xaml | 1 + 3 files changed, 24 insertions(+) diff --git a/src/cascadia/TerminalApp/TabBase.cpp b/src/cascadia/TerminalApp/TabBase.cpp index ef17fe3eb95..ec5edade70e 100644 --- a/src/cascadia/TerminalApp/TabBase.cpp +++ b/src/cascadia/TerminalApp/TabBase.cpp @@ -250,5 +250,25 @@ namespace winrt::TerminalApp::implementation tab->_RequestFocusActiveControlHandlers(); } }); + + TabViewItem().KeyUp({ get_weak(), &TabBase::_KeyHandler }); + } + + void TabBase::_KeyHandler(Windows::Foundation::IInspectable const& /*sender*/, + Windows::UI::Xaml::Input::KeyRoutedEventArgs const& e) + { + const auto key = e.OriginalKey(); + const auto scanCode = e.KeyStatus().ScanCode; + const auto coreWindow = CoreWindow::GetForCurrentThread(); + const auto ctrlDown = WI_IsFlagSet(coreWindow.GetKeyState(VirtualKey::Control), CoreVirtualKeyStates::Down); + const auto altDown = WI_IsFlagSet(coreWindow.GetKeyState(VirtualKey::Menu), CoreVirtualKeyStates::Down); + const auto shiftDown = WI_IsFlagSet(coreWindow.GetKeyState(VirtualKey::Shift), CoreVirtualKeyStates::Down); + + KeyChord kc{ ctrlDown, altDown, shiftDown, false, static_cast(key), static_cast(scanCode) }; + if (const auto cmd{ _actionMap.GetActionByKeyChord(kc) }) + { + _dispatch.DoAction(cmd.ActionAndArgs()); + e.Handled(true); + } } } diff --git a/src/cascadia/TerminalApp/TabBase.h b/src/cascadia/TerminalApp/TabBase.h index f98d3c24c90..34aed375c06 100644 --- a/src/cascadia/TerminalApp/TabBase.h +++ b/src/cascadia/TerminalApp/TabBase.h @@ -62,6 +62,9 @@ namespace winrt::TerminalApp::implementation winrt::fire_and_forget _UpdateSwitchToTabKeyChord(); void _UpdateToolTip(); + void _KeyHandler(Windows::Foundation::IInspectable const& /*sender*/, + Windows::UI::Xaml::Input::KeyRoutedEventArgs const& e); + friend class ::TerminalAppLocalTests::TabTests; }; } diff --git a/src/cascadia/TerminalApp/TerminalPage.xaml b/src/cascadia/TerminalApp/TerminalPage.xaml index e4be0e54a06..989bca40d7f 100644 --- a/src/cascadia/TerminalApp/TerminalPage.xaml +++ b/src/cascadia/TerminalApp/TerminalPage.xaml @@ -10,6 +10,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mux="using:Microsoft.UI.Xaml.Controls" Background="Transparent" + KeyDown="_KeyDownHandler" mc:Ignorable="d"> Date: Wed, 26 Jan 2022 12:08:09 -0600 Subject: [PATCH 2/3] I think this is a simpler solution, at least for #8480's sake --- src/cascadia/TerminalApp/TabBase.cpp | 2 +- src/cascadia/TerminalApp/TerminalPage.xaml | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/cascadia/TerminalApp/TabBase.cpp b/src/cascadia/TerminalApp/TabBase.cpp index ec5edade70e..639d9442e2a 100644 --- a/src/cascadia/TerminalApp/TabBase.cpp +++ b/src/cascadia/TerminalApp/TabBase.cpp @@ -251,7 +251,7 @@ namespace winrt::TerminalApp::implementation } }); - TabViewItem().KeyUp({ get_weak(), &TabBase::_KeyHandler }); + // TabViewItem().KeyUp({ get_weak(), &TabBase::_KeyHandler }); } void TabBase::_KeyHandler(Windows::Foundation::IInspectable const& /*sender*/, diff --git a/src/cascadia/TerminalApp/TerminalPage.xaml b/src/cascadia/TerminalApp/TerminalPage.xaml index 989bca40d7f..bf903482760 100644 --- a/src/cascadia/TerminalApp/TerminalPage.xaml +++ b/src/cascadia/TerminalApp/TerminalPage.xaml @@ -10,9 +10,18 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mux="using:Microsoft.UI.Xaml.Controls" Background="Transparent" - KeyDown="_KeyDownHandler" mc:Ignorable="d"> + + @@ -22,7 +31,8 @@ + Grid.Row="0" + KeyUp="_KeyDownHandler" /> Date: Wed, 26 Jan 2022 12:38:57 -0600 Subject: [PATCH 3/3] cleanup --- src/cascadia/TerminalApp/TabBase.cpp | 19 ------------------- src/cascadia/TerminalApp/TabBase.h | 3 --- src/cascadia/TerminalApp/TerminalPage.cpp | 6 ++++++ src/cascadia/TerminalApp/TerminalPage.xaml | 10 ---------- 4 files changed, 6 insertions(+), 32 deletions(-) diff --git a/src/cascadia/TerminalApp/TabBase.cpp b/src/cascadia/TerminalApp/TabBase.cpp index 639d9442e2a..3994a76c38f 100644 --- a/src/cascadia/TerminalApp/TabBase.cpp +++ b/src/cascadia/TerminalApp/TabBase.cpp @@ -250,25 +250,6 @@ namespace winrt::TerminalApp::implementation tab->_RequestFocusActiveControlHandlers(); } }); - - // TabViewItem().KeyUp({ get_weak(), &TabBase::_KeyHandler }); } - void TabBase::_KeyHandler(Windows::Foundation::IInspectable const& /*sender*/, - Windows::UI::Xaml::Input::KeyRoutedEventArgs const& e) - { - const auto key = e.OriginalKey(); - const auto scanCode = e.KeyStatus().ScanCode; - const auto coreWindow = CoreWindow::GetForCurrentThread(); - const auto ctrlDown = WI_IsFlagSet(coreWindow.GetKeyState(VirtualKey::Control), CoreVirtualKeyStates::Down); - const auto altDown = WI_IsFlagSet(coreWindow.GetKeyState(VirtualKey::Menu), CoreVirtualKeyStates::Down); - const auto shiftDown = WI_IsFlagSet(coreWindow.GetKeyState(VirtualKey::Shift), CoreVirtualKeyStates::Down); - - KeyChord kc{ ctrlDown, altDown, shiftDown, false, static_cast(key), static_cast(scanCode) }; - if (const auto cmd{ _actionMap.GetActionByKeyChord(kc) }) - { - _dispatch.DoAction(cmd.ActionAndArgs()); - e.Handled(true); - } - } } diff --git a/src/cascadia/TerminalApp/TabBase.h b/src/cascadia/TerminalApp/TabBase.h index 43db1839cbd..a04873f8905 100644 --- a/src/cascadia/TerminalApp/TabBase.h +++ b/src/cascadia/TerminalApp/TabBase.h @@ -63,9 +63,6 @@ namespace winrt::TerminalApp::implementation winrt::fire_and_forget _UpdateSwitchToTabKeyChord(); void _UpdateToolTip(); - void _KeyHandler(Windows::Foundation::IInspectable const& /*sender*/, - Windows::UI::Xaml::Input::KeyRoutedEventArgs const& e); - friend class ::TerminalAppLocalTests::TabTests; }; } diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index 1ef1087e2ae..6eb29cbfee8 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -1169,6 +1169,12 @@ namespace winrt::TerminalApp::implementation // Method Description: // - Called when the users pressed keyBindings while CommandPalette is open. + // - As of GH#8480, this is also bound to the TabRowControl's KeyUp event. + // That should only fire when focus is in the tab row, which is hard to + // do. Notably, that's possible: + // - When you have enough tabs to make the little scroll arrows appear, + // click one, then hit tab + // - When Narrator is in Scan mode (which is the a11y bug we're fixing here) // - This method is effectively an extract of TermControl::_KeyHandler and TermControl::_TryHandleKeyBinding. // Arguments: // - e: the KeyRoutedEventArgs containing info about the keystroke. diff --git a/src/cascadia/TerminalApp/TerminalPage.xaml b/src/cascadia/TerminalApp/TerminalPage.xaml index bf903482760..ad2fe2a3257 100644 --- a/src/cascadia/TerminalApp/TerminalPage.xaml +++ b/src/cascadia/TerminalApp/TerminalPage.xaml @@ -12,16 +12,6 @@ Background="Transparent" mc:Ignorable="d"> - -