From b8e9b3bf376357463ab74f291ee69ba948055444 Mon Sep 17 00:00:00 2001 From: Leon Liang Date: Wed, 12 Aug 2020 17:11:52 -0700 Subject: [PATCH 01/18] for science - nt/pt hijacked, unanchored ats now tabSearch --- src/cascadia/TerminalApp/ActionAndArgs.cpp | 7 ++-- src/cascadia/TerminalApp/ActionArgs.cpp | 19 --------- src/cascadia/TerminalApp/ActionArgs.h | 29 -------------- src/cascadia/TerminalApp/ActionArgs.idl | 5 --- .../TerminalApp/AppActionHandlers.cpp | 40 +++++++++---------- .../Resources/en-US/Resources.resw | 3 ++ .../TerminalApp/ShortcutActionDispatch.cpp | 4 +- .../TerminalApp/ShortcutActionDispatch.h | 2 +- .../TerminalApp/ShortcutActionDispatch.idl | 4 +- src/cascadia/TerminalApp/TerminalPage.cpp | 2 +- src/cascadia/TerminalApp/TerminalPage.h | 2 +- 11 files changed, 33 insertions(+), 84 deletions(-) diff --git a/src/cascadia/TerminalApp/ActionAndArgs.cpp b/src/cascadia/TerminalApp/ActionAndArgs.cpp index 150a31c92ea..6386bfbf03d 100644 --- a/src/cascadia/TerminalApp/ActionAndArgs.cpp +++ b/src/cascadia/TerminalApp/ActionAndArgs.cpp @@ -45,7 +45,7 @@ static constexpr std::string_view ExecuteCommandlineKey{ "wt" }; static constexpr std::string_view ToggleCommandPaletteKey{ "commandPalette" }; static constexpr std::string_view CloseOtherTabsKey{ "closeOtherTabs" }; static constexpr std::string_view CloseTabsAfterKey{ "closeTabsAfter" }; -static constexpr std::string_view ToggleTabSwitcherKey{ "tabSwitcher" }; +static constexpr std::string_view TabSearchKey{ "tabSearch" }; static constexpr std::string_view ActionKey{ "action" }; @@ -103,7 +103,7 @@ namespace winrt::TerminalApp::implementation { ToggleCommandPaletteKey, ShortcutAction::ToggleCommandPalette }, { CloseOtherTabsKey, ShortcutAction::CloseOtherTabs }, { CloseTabsAfterKey, ShortcutAction::CloseTabsAfter }, - { ToggleTabSwitcherKey, ShortcutAction::ToggleTabSwitcher }, + { TabSearchKey, ShortcutAction::TabSearch }, }; using ParseResult = std::tuple>; @@ -145,8 +145,6 @@ namespace winrt::TerminalApp::implementation { ShortcutAction::CloseTabsAfter, winrt::TerminalApp::implementation::CloseTabsAfterArgs::FromJson }, - { ShortcutAction::ToggleTabSwitcher, winrt::TerminalApp::implementation::ToggleTabSwitcherArgs::FromJson }, - { ShortcutAction::Invalid, nullptr }, }; @@ -301,6 +299,7 @@ namespace winrt::TerminalApp::implementation { ShortcutAction::ToggleCommandPalette, RS_(L"ToggleCommandPaletteCommandKey") }, { ShortcutAction::CloseOtherTabs, L"" }, // Intentionally omitted, must be generated by GenerateName { ShortcutAction::CloseTabsAfter, L"" }, // Intentionally omitted, must be generated by GenerateName + { ShortcutAction::TabSearch, RS_(L"TabSearchCommandKey") }, }; }(); diff --git a/src/cascadia/TerminalApp/ActionArgs.cpp b/src/cascadia/TerminalApp/ActionArgs.cpp index 1bc3983481d..844fda3e15b 100644 --- a/src/cascadia/TerminalApp/ActionArgs.cpp +++ b/src/cascadia/TerminalApp/ActionArgs.cpp @@ -20,7 +20,6 @@ #include "SetTabColorArgs.g.cpp" #include "RenameTabArgs.g.cpp" #include "ExecuteCommandlineArgs.g.cpp" -#include "ToggleTabSwitcherArgs.g.h" #include "Utils.h" @@ -317,22 +316,4 @@ namespace winrt::TerminalApp::implementation _Index) }; } - - winrt::hstring ToggleTabSwitcherArgs::GenerateName() const - { - // If there's an anchor key set, don't generate a name so that - // it won't show up in the command palette. Only an unanchored - // tab switcher should be able to be toggled from the palette. - // TODO: GH#7179 - once this goes in, make sure to hide the - // anchor mode command that was given a name in settings. - if (_AnchorKey != Windows::System::VirtualKey::None) - { - return L""; - } - else - { - return RS_(L"ToggleTabSwitcherCommandKey"); - } - } - } diff --git a/src/cascadia/TerminalApp/ActionArgs.h b/src/cascadia/TerminalApp/ActionArgs.h index d52cc3f4494..ba4824c7b46 100644 --- a/src/cascadia/TerminalApp/ActionArgs.h +++ b/src/cascadia/TerminalApp/ActionArgs.h @@ -22,7 +22,6 @@ #include "ExecuteCommandlineArgs.g.h" #include "CloseOtherTabsArgs.g.h" #include "CloseTabsAfterArgs.g.h" -#include "ToggleTabSwitcherArgs.g.h" #include "../../cascadia/inc/cppwinrt_utils.h" #include "Utils.h" @@ -544,34 +543,6 @@ namespace winrt::TerminalApp::implementation return { *args, {} }; } }; - - struct ToggleTabSwitcherArgs : public ToggleTabSwitcherArgsT - { - ToggleTabSwitcherArgs() = default; - GETSET_PROPERTY(Windows::System::VirtualKey, AnchorKey, Windows::System::VirtualKey::None); - - static constexpr std::string_view AnchorJsonKey{ "anchorKey" }; - - public: - hstring GenerateName() const; - - bool Equals(const IActionArgs& other) - { - auto otherAsUs = other.try_as(); - if (otherAsUs) - { - return otherAsUs->_AnchorKey == _AnchorKey; - } - return false; - }; - static FromJsonResult FromJson(const Json::Value& json) - { - // LOAD BEARING: Not using make_self here _will_ break you in the future! - auto args = winrt::make_self(); - JsonUtils::GetValueForKey(json, AnchorJsonKey, args->_AnchorKey); - return { *args, {} }; - } - }; } namespace winrt::TerminalApp::factory_implementation diff --git a/src/cascadia/TerminalApp/ActionArgs.idl b/src/cascadia/TerminalApp/ActionArgs.idl index ee50771eb94..8b0c73debc0 100644 --- a/src/cascadia/TerminalApp/ActionArgs.idl +++ b/src/cascadia/TerminalApp/ActionArgs.idl @@ -140,9 +140,4 @@ namespace TerminalApp { UInt32 Index { get; }; }; - - [default_interface] runtimeclass ToggleTabSwitcherArgs : IActionArgs - { - Windows.System.VirtualKey AnchorKey { get; }; - }; } diff --git a/src/cascadia/TerminalApp/AppActionHandlers.cpp b/src/cascadia/TerminalApp/AppActionHandlers.cpp index 80a06e733de..dea75831ced 100644 --- a/src/cascadia/TerminalApp/AppActionHandlers.cpp +++ b/src/cascadia/TerminalApp/AppActionHandlers.cpp @@ -78,14 +78,26 @@ namespace winrt::TerminalApp::implementation void TerminalPage::_HandleNextTab(const IInspectable& /*sender*/, const TerminalApp::ActionEventArgs& args) { - _SelectNextTab(true); + auto opt = _GetFocusedTabIndex(); + uint32_t startIdx = opt ? *opt : 0; + startIdx = (startIdx + _tabs.Size() + 1) % _tabs.Size(); + + CommandPalette().EnableTabSwitcherMode(VirtualKey::Control, startIdx); + CommandPalette().Visibility(Visibility::Visible); + args.Handled(true); } void TerminalPage::_HandlePrevTab(const IInspectable& /*sender*/, const TerminalApp::ActionEventArgs& args) { - _SelectNextTab(false); + auto opt = _GetFocusedTabIndex(); + uint32_t startIdx = opt ? *opt : 0; + startIdx = (startIdx + _tabs.Size() - 1) % _tabs.Size(); + + CommandPalette().EnableTabSwitcherMode(VirtualKey::Control, startIdx); + CommandPalette().Visibility(Visibility::Visible); + args.Handled(true); } @@ -454,27 +466,15 @@ namespace winrt::TerminalApp::implementation } } - void TerminalPage::_HandleToggleTabSwitcher(const IInspectable& /*sender*/, - const TerminalApp::ActionEventArgs& args) + void TerminalPage::_HandleOpenTabSearch(const IInspectable& /*sender*/, + const TerminalApp::ActionEventArgs& args) { - if (const auto& realArgs = args.ActionArgs().try_as()) - { - auto anchorKey = realArgs.AnchorKey(); + auto opt = _GetFocusedTabIndex(); + uint32_t startIdx = opt ? *opt : 0; - auto opt = _GetFocusedTabIndex(); - uint32_t startIdx = opt ? *opt : 0; + CommandPalette().EnableTabSwitcherMode(VirtualKey::None, startIdx); + CommandPalette().Visibility(Visibility::Visible); - if (anchorKey != VirtualKey::None) - { - // TODO: GH#7178 - delta should also have the option of being -1, in the case when - // a user decides to open the tab switcher going to the prev tab. - int delta = 1; - startIdx = (startIdx + _tabs.Size() + delta) % _tabs.Size(); - } - - CommandPalette().EnableTabSwitcherMode(anchorKey, startIdx); - CommandPalette().Visibility(Visibility::Visible); - } args.Handled(true); } } diff --git a/src/cascadia/TerminalApp/Resources/en-US/Resources.resw b/src/cascadia/TerminalApp/Resources/en-US/Resources.resw index c8951fac9f2..a98f391ac92 100644 --- a/src/cascadia/TerminalApp/Resources/en-US/Resources.resw +++ b/src/cascadia/TerminalApp/Resources/en-US/Resources.resw @@ -569,6 +569,9 @@ Close tabs after index {0} {0} will be replaced with a number + + Tab Search + Tab Switcher diff --git a/src/cascadia/TerminalApp/ShortcutActionDispatch.cpp b/src/cascadia/TerminalApp/ShortcutActionDispatch.cpp index 20a43791c2d..cce86db1988 100644 --- a/src/cascadia/TerminalApp/ShortcutActionDispatch.cpp +++ b/src/cascadia/TerminalApp/ShortcutActionDispatch.cpp @@ -226,9 +226,9 @@ namespace winrt::TerminalApp::implementation _CloseTabsAfterHandlers(*this, *eventArgs); break; } - case ShortcutAction::ToggleTabSwitcher: + case ShortcutAction::TabSearch: { - _ToggleTabSwitcherHandlers(*this, *eventArgs); + _TabSearchHandlers(*this, *eventArgs); break; } default: diff --git a/src/cascadia/TerminalApp/ShortcutActionDispatch.h b/src/cascadia/TerminalApp/ShortcutActionDispatch.h index 9da3aadcdf2..caecb41ef77 100644 --- a/src/cascadia/TerminalApp/ShortcutActionDispatch.h +++ b/src/cascadia/TerminalApp/ShortcutActionDispatch.h @@ -60,7 +60,7 @@ namespace winrt::TerminalApp::implementation TYPED_EVENT(ExecuteCommandline, TerminalApp::ShortcutActionDispatch, TerminalApp::ActionEventArgs); TYPED_EVENT(CloseOtherTabs, TerminalApp::ShortcutActionDispatch, TerminalApp::ActionEventArgs); TYPED_EVENT(CloseTabsAfter, TerminalApp::ShortcutActionDispatch, TerminalApp::ActionEventArgs); - TYPED_EVENT(ToggleTabSwitcher, TerminalApp::ShortcutActionDispatch, TerminalApp::ActionEventArgs); + TYPED_EVENT(TabSearch, TerminalApp::ShortcutActionDispatch, TerminalApp::ActionEventArgs); // clang-format on private: diff --git a/src/cascadia/TerminalApp/ShortcutActionDispatch.idl b/src/cascadia/TerminalApp/ShortcutActionDispatch.idl index e13c0433565..c54c41a884c 100644 --- a/src/cascadia/TerminalApp/ShortcutActionDispatch.idl +++ b/src/cascadia/TerminalApp/ShortcutActionDispatch.idl @@ -46,7 +46,7 @@ namespace TerminalApp ToggleCommandPalette, CloseOtherTabs, CloseTabsAfter, - ToggleTabSwitcher + TabSearch }; [default_interface] runtimeclass ActionAndArgs { @@ -97,6 +97,6 @@ namespace TerminalApp event Windows.Foundation.TypedEventHandler ExecuteCommandline; event Windows.Foundation.TypedEventHandler CloseOtherTabs; event Windows.Foundation.TypedEventHandler CloseTabsAfter; - event Windows.Foundation.TypedEventHandler ToggleTabSwitcher; + event Windows.Foundation.TypedEventHandler TabSearch; } } diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index 22547b2e005..ab8f599a18f 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -916,7 +916,7 @@ namespace winrt::TerminalApp::implementation _actionDispatch->ExecuteCommandline({ this, &TerminalPage::_HandleExecuteCommandline }); _actionDispatch->CloseOtherTabs({ this, &TerminalPage::_HandleCloseOtherTabs }); _actionDispatch->CloseTabsAfter({ this, &TerminalPage::_HandleCloseTabsAfter }); - _actionDispatch->ToggleTabSwitcher({ this, &TerminalPage::_HandleToggleTabSwitcher }); + _actionDispatch->TabSearch({ this, &TerminalPage::_HandleOpenTabSearch }); } // Method Description: diff --git a/src/cascadia/TerminalApp/TerminalPage.h b/src/cascadia/TerminalApp/TerminalPage.h index d89f96ca931..142a3f7c510 100644 --- a/src/cascadia/TerminalApp/TerminalPage.h +++ b/src/cascadia/TerminalApp/TerminalPage.h @@ -231,7 +231,7 @@ namespace winrt::TerminalApp::implementation void _HandleToggleCommandPalette(const IInspectable& sender, const TerminalApp::ActionEventArgs& args); void _HandleCloseOtherTabs(const IInspectable& sender, const TerminalApp::ActionEventArgs& args); void _HandleCloseTabsAfter(const IInspectable& sender, const TerminalApp::ActionEventArgs& args); - void _HandleToggleTabSwitcher(const IInspectable& sender, const TerminalApp::ActionEventArgs& args); + void _HandleOpenTabSearch(const IInspectable& sender, const TerminalApp::ActionEventArgs& args); // Make sure to hook new actions up in _RegisterActionCallbacks! #pragma endregion From e4de51a3d17c3dab90dcb922031370023629c37c Mon Sep 17 00:00:00 2001 From: Leon Liang Date: Thu, 13 Aug 2020 15:09:50 -0700 Subject: [PATCH 02/18] change keyup to select on any modifier release --- src/cascadia/TerminalApp/CommandPalette.cpp | 48 ++++++++------------- 1 file changed, 18 insertions(+), 30 deletions(-) diff --git a/src/cascadia/TerminalApp/CommandPalette.cpp b/src/cascadia/TerminalApp/CommandPalette.cpp index 962478d0677..8b28ba50766 100644 --- a/src/cascadia/TerminalApp/CommandPalette.cpp +++ b/src/cascadia/TerminalApp/CommandPalette.cpp @@ -49,18 +49,10 @@ namespace winrt::TerminalApp::implementation RegisterPropertyChangedCallback(UIElement::VisibilityProperty(), [this](auto&&, auto&&) { if (Visibility() == Visibility::Visible) { - if (_currentMode == CommandPaletteMode::TabSwitcherMode) + if (_currentMode == CommandPaletteMode::TabSwitcherMode && _anchorKey != VirtualKey::None) { - if (_anchorKey != VirtualKey::None) - { - _searchBox().Visibility(Visibility::Collapsed); - _filteredActionsView().Focus(FocusState::Keyboard); - } - else - { - _searchBox().Focus(FocusState::Programmatic); - } - + _searchBox().Visibility(Visibility::Collapsed); + _filteredActionsView().Focus(FocusState::Keyboard); _filteredActionsView().SelectedIndex(_switcherStartIdx); _filteredActionsView().ScrollIntoView(_filteredActionsView().SelectedItem()); } @@ -204,27 +196,26 @@ namespace winrt::TerminalApp::implementation void CommandPalette::_keyUpHandler(IInspectable const& /*sender*/, Windows::UI::Xaml::Input::KeyRoutedEventArgs const& e) { - auto key = e.OriginalKey(); - if (_currentMode == CommandPaletteMode::TabSwitcherMode) { - if (_anchorKey && key == _anchorKey.value()) + if (_anchorKey != VirtualKey::None) { - // Once the user lifts the anchor key, we'll switch to the currently selected tab - // then close the tab switcher. + auto const ctrlDown = WI_IsFlagSet(CoreWindow::GetForCurrentThread().GetKeyState(winrt::Windows::System::VirtualKey::Control), CoreVirtualKeyStates::Down); + auto const altDown = WI_IsFlagSet(CoreWindow::GetForCurrentThread().GetKeyState(winrt::Windows::System::VirtualKey::Menu), CoreVirtualKeyStates::Down); + auto const shiftDown = WI_IsFlagSet(CoreWindow::GetForCurrentThread().GetKeyState(winrt::Windows::System::VirtualKey::Shift), CoreVirtualKeyStates::Down); - if (const auto selectedItem = _filteredActionsView().SelectedItem()) + if (!ctrlDown && !altDown && !shiftDown) { - if (const auto data = selectedItem.try_as()) + if (const auto selectedItem = _filteredActionsView().SelectedItem()) { - const auto actionAndArgs = data.Action(); - _dispatch.DoAction(actionAndArgs); - _updateFilteredActions(); - _dismissPalette(); + if (const auto data = selectedItem.try_as()) + { + _dispatchCommand(data); + } } - } - e.Handled(true); + e.Handled(true); + } } } } @@ -772,14 +763,11 @@ namespace winrt::TerminalApp::implementation // - void CommandPalette::UpdateTabIndices(const uint32_t startIdx) { - if (startIdx != _allTabActions.Size() - 1) + for (auto i = startIdx; i < _allTabActions.Size(); ++i) { - for (auto i = startIdx; i < _allTabActions.Size(); ++i) - { - auto command = _allTabActions.GetAt(i); + auto command = _allTabActions.GetAt(i); - command.Action().Args().as()->TabIndex(i); - } + command.Action().Args().as()->TabIndex(i); } } From 4fd1862aa627b811374be49b58fdfe145f0e0538 Mon Sep 17 00:00:00 2001 From: Leon Liang Date: Thu, 13 Aug 2020 15:36:55 -0700 Subject: [PATCH 03/18] add global setting to swap between boring tab switching and exciting tab switching --- .../TerminalApp/AppActionHandlers.cpp | 35 +++++++++++++------ .../TerminalApp/GlobalAppSettings.cpp | 4 +++ src/cascadia/TerminalApp/GlobalAppSettings.h | 1 + src/cascadia/TerminalApp/TerminalSettings.h | 2 ++ src/cascadia/TerminalApp/defaults.json | 1 + .../TerminalControl/IControlSettings.idl | 2 ++ 6 files changed, 35 insertions(+), 10 deletions(-) diff --git a/src/cascadia/TerminalApp/AppActionHandlers.cpp b/src/cascadia/TerminalApp/AppActionHandlers.cpp index dea75831ced..5b726d48d63 100644 --- a/src/cascadia/TerminalApp/AppActionHandlers.cpp +++ b/src/cascadia/TerminalApp/AppActionHandlers.cpp @@ -78,12 +78,20 @@ namespace winrt::TerminalApp::implementation void TerminalPage::_HandleNextTab(const IInspectable& /*sender*/, const TerminalApp::ActionEventArgs& args) { - auto opt = _GetFocusedTabIndex(); - uint32_t startIdx = opt ? *opt : 0; - startIdx = (startIdx + _tabs.Size() + 1) % _tabs.Size(); + if (_settings->GlobalSettings().UseTabSwitcher()) + { + auto opt = _GetFocusedTabIndex(); + uint32_t startIdx = opt ? *opt : 0; + startIdx = (startIdx + _tabs.Size() + 1) % _tabs.Size(); + + CommandPalette().EnableTabSwitcherMode(VirtualKey::Control, startIdx); + CommandPalette().Visibility(Visibility::Visible); + } + else + { + _SelectNextTab(true); + } - CommandPalette().EnableTabSwitcherMode(VirtualKey::Control, startIdx); - CommandPalette().Visibility(Visibility::Visible); args.Handled(true); } @@ -91,12 +99,19 @@ namespace winrt::TerminalApp::implementation void TerminalPage::_HandlePrevTab(const IInspectable& /*sender*/, const TerminalApp::ActionEventArgs& args) { - auto opt = _GetFocusedTabIndex(); - uint32_t startIdx = opt ? *opt : 0; - startIdx = (startIdx + _tabs.Size() - 1) % _tabs.Size(); + if (_settings->GlobalSettings().UseTabSwitcher()) + { + auto opt = _GetFocusedTabIndex(); + uint32_t startIdx = opt ? *opt : 0; + startIdx = (startIdx + _tabs.Size() - 1) % _tabs.Size(); - CommandPalette().EnableTabSwitcherMode(VirtualKey::Control, startIdx); - CommandPalette().Visibility(Visibility::Visible); + CommandPalette().EnableTabSwitcherMode(VirtualKey::Control, startIdx); + CommandPalette().Visibility(Visibility::Visible); + } + else + { + _SelectNextTab(false); + } args.Handled(true); } diff --git a/src/cascadia/TerminalApp/GlobalAppSettings.cpp b/src/cascadia/TerminalApp/GlobalAppSettings.cpp index afeca688c6d..485d4e8370c 100644 --- a/src/cascadia/TerminalApp/GlobalAppSettings.cpp +++ b/src/cascadia/TerminalApp/GlobalAppSettings.cpp @@ -36,6 +36,7 @@ static constexpr std::string_view ConfirmCloseAllKey{ "confirmCloseAllTabs" }; static constexpr std::string_view SnapToGridOnResizeKey{ "snapToGridOnResize" }; static constexpr std::string_view EnableStartupTaskKey{ "startOnUserLogin" }; static constexpr std::string_view AlwaysOnTopKey{ "alwaysOnTop" }; +static constexpr std::string_view UseTabSwitcherKey{ "useTabSwitcher" }; static constexpr std::string_view DebugFeaturesKey{ "debugFeatures" }; @@ -116,6 +117,7 @@ void GlobalAppSettings::ApplyToSettings(TerminalSettings& settings) const noexce settings.ForceFullRepaintRendering(_ForceFullRepaintRendering); settings.SoftwareRendering(_SoftwareRendering); settings.ForceVTInput(_ForceVTInput); + settings.UseTabSwitcher(_UseTabSwitcher); } // Method Description: @@ -179,6 +181,8 @@ void GlobalAppSettings::LayerJson(const Json::Value& json) JsonUtils::GetValueForKey(json, AlwaysOnTopKey, _AlwaysOnTop); + JsonUtils::GetValueForKey(json, UseTabSwitcherKey, _UseTabSwitcher); + // This is a helper lambda to get the keybindings and commands out of both // and array of objects. We'll use this twice, once on the legacy // `keybindings` key, and again on the newer `bindings` key. diff --git a/src/cascadia/TerminalApp/GlobalAppSettings.h b/src/cascadia/TerminalApp/GlobalAppSettings.h index ba51109fa0b..f0aad336ca4 100644 --- a/src/cascadia/TerminalApp/GlobalAppSettings.h +++ b/src/cascadia/TerminalApp/GlobalAppSettings.h @@ -80,6 +80,7 @@ class TerminalApp::GlobalAppSettings final GETSET_PROPERTY(bool, DebugFeaturesEnabled); // default value set in constructor GETSET_PROPERTY(bool, StartOnUserLogin, false); GETSET_PROPERTY(bool, AlwaysOnTop, false); + GETSET_PROPERTY(bool, UseTabSwitcher, false); private: std::optional _unparsedDefaultProfile; diff --git a/src/cascadia/TerminalApp/TerminalSettings.h b/src/cascadia/TerminalApp/TerminalSettings.h index 53a4ab3201d..b9c16d91655 100644 --- a/src/cascadia/TerminalApp/TerminalSettings.h +++ b/src/cascadia/TerminalApp/TerminalSettings.h @@ -97,6 +97,8 @@ namespace winrt::TerminalApp::implementation GETSET_PROPERTY(bool, SoftwareRendering, false); GETSET_PROPERTY(bool, ForceVTInput, false); + GETSET_PROPERTY(bool, UseTabSwitcher, false); + #pragma warning(pop) private: diff --git a/src/cascadia/TerminalApp/defaults.json b/src/cascadia/TerminalApp/defaults.json index a05668723f8..3349dfe6c82 100644 --- a/src/cascadia/TerminalApp/defaults.json +++ b/src/cascadia/TerminalApp/defaults.json @@ -18,6 +18,7 @@ "showTabsInTitlebar": true, "showTerminalTitleInTitlebar": true, "tabWidthMode": "equal", + "useTabSwitcher": false, // Miscellaneous "confirmCloseAllTabs": true, diff --git a/src/cascadia/TerminalControl/IControlSettings.idl b/src/cascadia/TerminalControl/IControlSettings.idl index 2f140a0a3f8..8d5645db26c 100644 --- a/src/cascadia/TerminalControl/IControlSettings.idl +++ b/src/cascadia/TerminalControl/IControlSettings.idl @@ -57,5 +57,7 @@ namespace Microsoft.Terminal.TerminalControl Boolean RetroTerminalEffect; Boolean ForceFullRepaintRendering; Boolean SoftwareRendering; + + Boolean UseTabSwitcher; }; } From 43241cfec83712447291b3062ce57762a761483b Mon Sep 17 00:00:00 2001 From: Leon Liang Date: Thu, 13 Aug 2020 16:26:33 -0700 Subject: [PATCH 04/18] now that we don't have a designated anchor key, change the var to anchoredMode --- src/cascadia/TerminalApp/AppActionHandlers.cpp | 8 ++++---- src/cascadia/TerminalApp/CommandPalette.cpp | 14 +++++++------- src/cascadia/TerminalApp/CommandPalette.h | 4 ++-- src/cascadia/TerminalApp/CommandPalette.idl | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/cascadia/TerminalApp/AppActionHandlers.cpp b/src/cascadia/TerminalApp/AppActionHandlers.cpp index 5b726d48d63..9e742cceb39 100644 --- a/src/cascadia/TerminalApp/AppActionHandlers.cpp +++ b/src/cascadia/TerminalApp/AppActionHandlers.cpp @@ -84,7 +84,7 @@ namespace winrt::TerminalApp::implementation uint32_t startIdx = opt ? *opt : 0; startIdx = (startIdx + _tabs.Size() + 1) % _tabs.Size(); - CommandPalette().EnableTabSwitcherMode(VirtualKey::Control, startIdx); + CommandPalette().EnableTabSwitcherMode(true, startIdx); CommandPalette().Visibility(Visibility::Visible); } else @@ -105,7 +105,7 @@ namespace winrt::TerminalApp::implementation uint32_t startIdx = opt ? *opt : 0; startIdx = (startIdx + _tabs.Size() - 1) % _tabs.Size(); - CommandPalette().EnableTabSwitcherMode(VirtualKey::Control, startIdx); + CommandPalette().EnableTabSwitcherMode(true, startIdx); CommandPalette().Visibility(Visibility::Visible); } else @@ -482,12 +482,12 @@ namespace winrt::TerminalApp::implementation } void TerminalPage::_HandleOpenTabSearch(const IInspectable& /*sender*/, - const TerminalApp::ActionEventArgs& args) + const TerminalApp::ActionEventArgs& args) { auto opt = _GetFocusedTabIndex(); uint32_t startIdx = opt ? *opt : 0; - CommandPalette().EnableTabSwitcherMode(VirtualKey::None, startIdx); + CommandPalette().EnableTabSwitcherMode(false, startIdx); CommandPalette().Visibility(Visibility::Visible); args.Handled(true); diff --git a/src/cascadia/TerminalApp/CommandPalette.cpp b/src/cascadia/TerminalApp/CommandPalette.cpp index 8b28ba50766..54d6d17ba69 100644 --- a/src/cascadia/TerminalApp/CommandPalette.cpp +++ b/src/cascadia/TerminalApp/CommandPalette.cpp @@ -22,7 +22,7 @@ using namespace winrt::Windows::Foundation::Collections; namespace winrt::TerminalApp::implementation { CommandPalette::CommandPalette() : - _anchorKey{ VirtualKey::None }, + _anchoredMode{ false }, _switcherStartIdx{ 0 } { InitializeComponent(); @@ -49,7 +49,7 @@ namespace winrt::TerminalApp::implementation RegisterPropertyChangedCallback(UIElement::VisibilityProperty(), [this](auto&&, auto&&) { if (Visibility() == Visibility::Visible) { - if (_currentMode == CommandPaletteMode::TabSwitcherMode && _anchorKey != VirtualKey::None) + if (_currentMode == CommandPaletteMode::TabSwitcherMode && _anchoredMode) { _searchBox().Visibility(Visibility::Collapsed); _filteredActionsView().Focus(FocusState::Keyboard); @@ -83,7 +83,7 @@ namespace winrt::TerminalApp::implementation // when the ListView has been measured out and is ready, and we'll immediately // revoke the handler because we only needed to handle it once on initialization. _sizeChangedRevoker = _filteredActionsView().SizeChanged(winrt::auto_revoke, [this](auto /*s*/, auto /*e*/) { - if (_currentMode == CommandPaletteMode::TabSwitcherMode && _anchorKey != VirtualKey::None) + if (_currentMode == CommandPaletteMode::TabSwitcherMode && _anchoredMode) { _filteredActionsView().Focus(FocusState::Keyboard); } @@ -125,7 +125,7 @@ namespace winrt::TerminalApp::implementation // a really widely used keyboard navigation key. if (_currentMode == CommandPaletteMode::TabSwitcherMode && key == VirtualKey::Tab && - _anchorKey != VirtualKey::None) + _anchoredMode) { auto const state = CoreWindow::GetForCurrentThread().GetKeyState(winrt::Windows::System::VirtualKey::Shift); if (WI_IsFlagSet(state, CoreVirtualKeyStates::Down)) @@ -198,7 +198,7 @@ namespace winrt::TerminalApp::implementation { if (_currentMode == CommandPaletteMode::TabSwitcherMode) { - if (_anchorKey != VirtualKey::None) + if (_anchoredMode) { auto const ctrlDown = WI_IsFlagSet(CoreWindow::GetForCurrentThread().GetKeyState(winrt::Windows::System::VirtualKey::Control), CoreVirtualKeyStates::Down); auto const altDown = WI_IsFlagSet(CoreWindow::GetForCurrentThread().GetKeyState(winrt::Windows::System::VirtualKey::Menu), CoreVirtualKeyStates::Down); @@ -829,10 +829,10 @@ namespace winrt::TerminalApp::implementation } } - void CommandPalette::EnableTabSwitcherMode(const VirtualKey& anchorKey, const uint32_t startIdx) + void CommandPalette::EnableTabSwitcherMode(const bool anchoredMode, const uint32_t startIdx) { _switcherStartIdx = startIdx; - _anchorKey = anchorKey; + _anchoredMode = anchoredMode; _switchToMode(CommandPaletteMode::TabSwitcherMode); _updateFilteredActions(); } diff --git a/src/cascadia/TerminalApp/CommandPalette.h b/src/cascadia/TerminalApp/CommandPalette.h index b062b42003c..080e1215eb8 100644 --- a/src/cascadia/TerminalApp/CommandPalette.h +++ b/src/cascadia/TerminalApp/CommandPalette.h @@ -26,7 +26,7 @@ namespace winrt::TerminalApp::implementation void SetDispatch(const winrt::TerminalApp::ShortcutActionDispatch& dispatch); // Tab Switcher - void EnableTabSwitcherMode(const Windows::System::VirtualKey& anchorKey, const uint32_t startIdx); + void EnableTabSwitcherMode(const bool anchoredMode, const uint32_t startIdx); void OnTabsChanged(const Windows::Foundation::IInspectable& s, const Windows::Foundation::Collections::IVectorChangedEventArgs& e); WINRT_CALLBACK(PropertyChanged, Windows::UI::Xaml::Data::PropertyChangedEventHandler); @@ -69,7 +69,7 @@ namespace winrt::TerminalApp::implementation void _switchToMode(CommandPaletteMode mode); // Tab Switcher - std::optional _anchorKey; + bool _anchoredMode; void GenerateCommandForTab(const uint32_t idx, bool inserted, winrt::TerminalApp::Tab& tab); void UpdateTabIndices(const uint32_t startIdx); Windows::Foundation::Collections::IVector _allTabActions{ nullptr }; diff --git a/src/cascadia/TerminalApp/CommandPalette.idl b/src/cascadia/TerminalApp/CommandPalette.idl index 8286077a4e4..2c7a638690a 100644 --- a/src/cascadia/TerminalApp/CommandPalette.idl +++ b/src/cascadia/TerminalApp/CommandPalette.idl @@ -20,7 +20,7 @@ namespace TerminalApp void SetDispatch(ShortcutActionDispatch dispatch); - void EnableTabSwitcherMode(Windows.System.VirtualKey anchorKey, UInt32 startIdx); + void EnableTabSwitcherMode(Boolean anchoredMode, UInt32 startIdx); void OnTabsChanged(IInspectable s, Windows.Foundation.Collections.IVectorChangedEventArgs e); } } From e15672e9c09bd23f86831b0e2c9feb3f58ee4dcb Mon Sep 17 00:00:00 2001 From: Leon Liang Date: Fri, 14 Aug 2020 13:55:39 -0700 Subject: [PATCH 05/18] go back to anchorKey, priority set anchorkey at appactionhandlers level --- .../TerminalApp/AppActionHandlers.cpp | 22 +++++++++-- src/cascadia/TerminalApp/CommandPalette.cpp | 37 ++++++++----------- src/cascadia/TerminalApp/CommandPalette.h | 4 +- src/cascadia/TerminalApp/CommandPalette.idl | 2 +- 4 files changed, 37 insertions(+), 28 deletions(-) diff --git a/src/cascadia/TerminalApp/AppActionHandlers.cpp b/src/cascadia/TerminalApp/AppActionHandlers.cpp index 9e742cceb39..a6a5ca39b04 100644 --- a/src/cascadia/TerminalApp/AppActionHandlers.cpp +++ b/src/cascadia/TerminalApp/AppActionHandlers.cpp @@ -80,11 +80,19 @@ namespace winrt::TerminalApp::implementation { if (_settings->GlobalSettings().UseTabSwitcher()) { + auto const ctrlDown = WI_IsFlagSet(CoreWindow::GetForCurrentThread().GetKeyState(winrt::Windows::System::VirtualKey::Control), CoreVirtualKeyStates::Down); + auto const altDown = WI_IsFlagSet(CoreWindow::GetForCurrentThread().GetKeyState(winrt::Windows::System::VirtualKey::Menu), CoreVirtualKeyStates::Down); + auto const shiftDown = WI_IsFlagSet(CoreWindow::GetForCurrentThread().GetKeyState(winrt::Windows::System::VirtualKey::Shift), CoreVirtualKeyStates::Down); + + // Choose one of the modifier keys as the anchor key in priority order. + // So even if the user decides to use multiple modifiers in the keybinding, we'll only listen to one's KeyUp. + auto anchorKey = ctrlDown ? VirtualKey::Control : altDown ? VirtualKey::Menu : shiftDown ? VirtualKey::Shift : VirtualKey::None; + auto opt = _GetFocusedTabIndex(); uint32_t startIdx = opt ? *opt : 0; startIdx = (startIdx + _tabs.Size() + 1) % _tabs.Size(); - CommandPalette().EnableTabSwitcherMode(true, startIdx); + CommandPalette().EnableTabSwitcherMode(anchorKey, startIdx); CommandPalette().Visibility(Visibility::Visible); } else @@ -101,11 +109,19 @@ namespace winrt::TerminalApp::implementation { if (_settings->GlobalSettings().UseTabSwitcher()) { + auto const ctrlDown = WI_IsFlagSet(CoreWindow::GetForCurrentThread().GetKeyState(winrt::Windows::System::VirtualKey::Control), CoreVirtualKeyStates::Down); + auto const altDown = WI_IsFlagSet(CoreWindow::GetForCurrentThread().GetKeyState(winrt::Windows::System::VirtualKey::Menu), CoreVirtualKeyStates::Down); + auto const shiftDown = WI_IsFlagSet(CoreWindow::GetForCurrentThread().GetKeyState(winrt::Windows::System::VirtualKey::Shift), CoreVirtualKeyStates::Down); + + // Choose one of the modifier keys as the anchor key in priority order. + // So even if the user decides to use multiple modifiers in the keybinding, we'll only listen to one's KeyUp. + auto anchorKey = ctrlDown ? VirtualKey::Control : altDown ? VirtualKey::Menu : shiftDown ? VirtualKey::Shift : VirtualKey::None; + auto opt = _GetFocusedTabIndex(); uint32_t startIdx = opt ? *opt : 0; startIdx = (startIdx + _tabs.Size() - 1) % _tabs.Size(); - CommandPalette().EnableTabSwitcherMode(true, startIdx); + CommandPalette().EnableTabSwitcherMode(anchorKey, startIdx); CommandPalette().Visibility(Visibility::Visible); } else @@ -487,7 +503,7 @@ namespace winrt::TerminalApp::implementation auto opt = _GetFocusedTabIndex(); uint32_t startIdx = opt ? *opt : 0; - CommandPalette().EnableTabSwitcherMode(false, startIdx); + CommandPalette().EnableTabSwitcherMode(VirtualKey::None, startIdx); CommandPalette().Visibility(Visibility::Visible); args.Handled(true); diff --git a/src/cascadia/TerminalApp/CommandPalette.cpp b/src/cascadia/TerminalApp/CommandPalette.cpp index 54d6d17ba69..2821bff968d 100644 --- a/src/cascadia/TerminalApp/CommandPalette.cpp +++ b/src/cascadia/TerminalApp/CommandPalette.cpp @@ -22,7 +22,7 @@ using namespace winrt::Windows::Foundation::Collections; namespace winrt::TerminalApp::implementation { CommandPalette::CommandPalette() : - _anchoredMode{ false }, + _anchorKey{ VirtualKey::None }, _switcherStartIdx{ 0 } { InitializeComponent(); @@ -49,7 +49,7 @@ namespace winrt::TerminalApp::implementation RegisterPropertyChangedCallback(UIElement::VisibilityProperty(), [this](auto&&, auto&&) { if (Visibility() == Visibility::Visible) { - if (_currentMode == CommandPaletteMode::TabSwitcherMode && _anchoredMode) + if (_currentMode == CommandPaletteMode::TabSwitcherMode && _anchorKey != VirtualKey::None) { _searchBox().Visibility(Visibility::Collapsed); _filteredActionsView().Focus(FocusState::Keyboard); @@ -83,7 +83,7 @@ namespace winrt::TerminalApp::implementation // when the ListView has been measured out and is ready, and we'll immediately // revoke the handler because we only needed to handle it once on initialization. _sizeChangedRevoker = _filteredActionsView().SizeChanged(winrt::auto_revoke, [this](auto /*s*/, auto /*e*/) { - if (_currentMode == CommandPaletteMode::TabSwitcherMode && _anchoredMode) + if (_currentMode == CommandPaletteMode::TabSwitcherMode && _anchorKey != VirtualKey::None) { _filteredActionsView().Focus(FocusState::Keyboard); } @@ -125,7 +125,7 @@ namespace winrt::TerminalApp::implementation // a really widely used keyboard navigation key. if (_currentMode == CommandPaletteMode::TabSwitcherMode && key == VirtualKey::Tab && - _anchoredMode) + _anchorKey != VirtualKey::None) { auto const state = CoreWindow::GetForCurrentThread().GetKeyState(winrt::Windows::System::VirtualKey::Shift); if (WI_IsFlagSet(state, CoreVirtualKeyStates::Down)) @@ -196,27 +196,20 @@ namespace winrt::TerminalApp::implementation void CommandPalette::_keyUpHandler(IInspectable const& /*sender*/, Windows::UI::Xaml::Input::KeyRoutedEventArgs const& e) { - if (_currentMode == CommandPaletteMode::TabSwitcherMode) + // TODO: AltKey ups aren't handled like this. + if (_currentMode == CommandPaletteMode::TabSwitcherMode && + _anchorKey != VirtualKey::None && + e.OriginalKey() == _anchorKey) { - if (_anchoredMode) + if (const auto selectedItem = _filteredActionsView().SelectedItem()) { - auto const ctrlDown = WI_IsFlagSet(CoreWindow::GetForCurrentThread().GetKeyState(winrt::Windows::System::VirtualKey::Control), CoreVirtualKeyStates::Down); - auto const altDown = WI_IsFlagSet(CoreWindow::GetForCurrentThread().GetKeyState(winrt::Windows::System::VirtualKey::Menu), CoreVirtualKeyStates::Down); - auto const shiftDown = WI_IsFlagSet(CoreWindow::GetForCurrentThread().GetKeyState(winrt::Windows::System::VirtualKey::Shift), CoreVirtualKeyStates::Down); - - if (!ctrlDown && !altDown && !shiftDown) + if (const auto data = selectedItem.try_as()) { - if (const auto selectedItem = _filteredActionsView().SelectedItem()) - { - if (const auto data = selectedItem.try_as()) - { - _dispatchCommand(data); - } - } - - e.Handled(true); + _dispatchCommand(data); } } + + e.Handled(true); } } @@ -829,10 +822,10 @@ namespace winrt::TerminalApp::implementation } } - void CommandPalette::EnableTabSwitcherMode(const bool anchoredMode, const uint32_t startIdx) + void CommandPalette::EnableTabSwitcherMode(const VirtualKey& anchorKey, const uint32_t startIdx) { _switcherStartIdx = startIdx; - _anchoredMode = anchoredMode; + _anchorKey = anchorKey; _switchToMode(CommandPaletteMode::TabSwitcherMode); _updateFilteredActions(); } diff --git a/src/cascadia/TerminalApp/CommandPalette.h b/src/cascadia/TerminalApp/CommandPalette.h index 080e1215eb8..f7bc5ba8f9f 100644 --- a/src/cascadia/TerminalApp/CommandPalette.h +++ b/src/cascadia/TerminalApp/CommandPalette.h @@ -26,7 +26,7 @@ namespace winrt::TerminalApp::implementation void SetDispatch(const winrt::TerminalApp::ShortcutActionDispatch& dispatch); // Tab Switcher - void EnableTabSwitcherMode(const bool anchoredMode, const uint32_t startIdx); + void EnableTabSwitcherMode(const Windows::System::VirtualKey& anchorKey, const uint32_t startIdx); void OnTabsChanged(const Windows::Foundation::IInspectable& s, const Windows::Foundation::Collections::IVectorChangedEventArgs& e); WINRT_CALLBACK(PropertyChanged, Windows::UI::Xaml::Data::PropertyChangedEventHandler); @@ -69,7 +69,7 @@ namespace winrt::TerminalApp::implementation void _switchToMode(CommandPaletteMode mode); // Tab Switcher - bool _anchoredMode; + winrt::Windows::System::VirtualKey _anchorKey; void GenerateCommandForTab(const uint32_t idx, bool inserted, winrt::TerminalApp::Tab& tab); void UpdateTabIndices(const uint32_t startIdx); Windows::Foundation::Collections::IVector _allTabActions{ nullptr }; diff --git a/src/cascadia/TerminalApp/CommandPalette.idl b/src/cascadia/TerminalApp/CommandPalette.idl index 2c7a638690a..8286077a4e4 100644 --- a/src/cascadia/TerminalApp/CommandPalette.idl +++ b/src/cascadia/TerminalApp/CommandPalette.idl @@ -20,7 +20,7 @@ namespace TerminalApp void SetDispatch(ShortcutActionDispatch dispatch); - void EnableTabSwitcherMode(Boolean anchoredMode, UInt32 startIdx); + void EnableTabSwitcherMode(Windows.System.VirtualKey anchorKey, UInt32 startIdx); void OnTabsChanged(IInspectable s, Windows.Foundation.Collections.IVectorChangedEventArgs e); } } From 33a513cb5fa4c132e6b41b25523ab150c908e4f9 Mon Sep 17 00:00:00 2001 From: Leon Liang Date: Fri, 14 Aug 2020 15:45:38 -0700 Subject: [PATCH 06/18] detect modifiers pressed at handlenT/handlepT, do boring switch if no mods --- .../TerminalApp/AppActionHandlers.cpp | 44 ++++++++++++------- src/cascadia/TerminalApp/CommandPalette.cpp | 2 +- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/src/cascadia/TerminalApp/AppActionHandlers.cpp b/src/cascadia/TerminalApp/AppActionHandlers.cpp index a6a5ca39b04..d3842f3e201 100644 --- a/src/cascadia/TerminalApp/AppActionHandlers.cpp +++ b/src/cascadia/TerminalApp/AppActionHandlers.cpp @@ -84,16 +84,22 @@ namespace winrt::TerminalApp::implementation auto const altDown = WI_IsFlagSet(CoreWindow::GetForCurrentThread().GetKeyState(winrt::Windows::System::VirtualKey::Menu), CoreVirtualKeyStates::Down); auto const shiftDown = WI_IsFlagSet(CoreWindow::GetForCurrentThread().GetKeyState(winrt::Windows::System::VirtualKey::Shift), CoreVirtualKeyStates::Down); - // Choose one of the modifier keys as the anchor key in priority order. - // So even if the user decides to use multiple modifiers in the keybinding, we'll only listen to one's KeyUp. + // One or more of the modifiers should be pressed when invoking next/prev Tab. In priority order, choose one as the anchor. + // If none of the modifier keys were pressed while invoking next/prev Tab, TODO: idk wtf they're thinking so just do classic nT/pT auto anchorKey = ctrlDown ? VirtualKey::Control : altDown ? VirtualKey::Menu : shiftDown ? VirtualKey::Shift : VirtualKey::None; + if (anchorKey == VirtualKey::None) + { + _SelectNextTab(true); + } + else + { + auto opt = _GetFocusedTabIndex(); + uint32_t startIdx = opt ? *opt : 0; + startIdx = (startIdx + _tabs.Size() + 1) % _tabs.Size(); - auto opt = _GetFocusedTabIndex(); - uint32_t startIdx = opt ? *opt : 0; - startIdx = (startIdx + _tabs.Size() + 1) % _tabs.Size(); - - CommandPalette().EnableTabSwitcherMode(anchorKey, startIdx); - CommandPalette().Visibility(Visibility::Visible); + CommandPalette().EnableTabSwitcherMode(anchorKey, startIdx); + CommandPalette().Visibility(Visibility::Visible); + } } else { @@ -113,16 +119,22 @@ namespace winrt::TerminalApp::implementation auto const altDown = WI_IsFlagSet(CoreWindow::GetForCurrentThread().GetKeyState(winrt::Windows::System::VirtualKey::Menu), CoreVirtualKeyStates::Down); auto const shiftDown = WI_IsFlagSet(CoreWindow::GetForCurrentThread().GetKeyState(winrt::Windows::System::VirtualKey::Shift), CoreVirtualKeyStates::Down); - // Choose one of the modifier keys as the anchor key in priority order. - // So even if the user decides to use multiple modifiers in the keybinding, we'll only listen to one's KeyUp. + // One or more of the modifiers should be pressed when invoking next/prev Tab. In priority order, choose one as the anchor. + // If none of the modifier keys were pressed while invoking next/prev Tab, TODO: idk wtf they're thinking so just do classic nT/pT auto anchorKey = ctrlDown ? VirtualKey::Control : altDown ? VirtualKey::Menu : shiftDown ? VirtualKey::Shift : VirtualKey::None; + if (anchorKey == VirtualKey::None) + { + _SelectNextTab(false); + } + else + { + auto opt = _GetFocusedTabIndex(); + uint32_t startIdx = opt ? *opt : 0; + startIdx = (startIdx + _tabs.Size() - 1) % _tabs.Size(); - auto opt = _GetFocusedTabIndex(); - uint32_t startIdx = opt ? *opt : 0; - startIdx = (startIdx + _tabs.Size() - 1) % _tabs.Size(); - - CommandPalette().EnableTabSwitcherMode(anchorKey, startIdx); - CommandPalette().Visibility(Visibility::Visible); + CommandPalette().EnableTabSwitcherMode(anchorKey, startIdx); + CommandPalette().Visibility(Visibility::Visible); + } } else { diff --git a/src/cascadia/TerminalApp/CommandPalette.cpp b/src/cascadia/TerminalApp/CommandPalette.cpp index 2821bff968d..d8b8b9ef2ed 100644 --- a/src/cascadia/TerminalApp/CommandPalette.cpp +++ b/src/cascadia/TerminalApp/CommandPalette.cpp @@ -196,7 +196,7 @@ namespace winrt::TerminalApp::implementation void CommandPalette::_keyUpHandler(IInspectable const& /*sender*/, Windows::UI::Xaml::Input::KeyRoutedEventArgs const& e) { - // TODO: AltKey ups aren't handled like this. + // Alt KeyUps are just not going to be detected unfortunately. if (_currentMode == CommandPaletteMode::TabSwitcherMode && _anchorKey != VirtualKey::None && e.OriginalKey() == _anchorKey) From 9d188f0237512eeff05b92718e798350e92c37d7 Mon Sep 17 00:00:00 2001 From: Leon Liang Date: Mon, 17 Aug 2020 14:24:55 -0700 Subject: [PATCH 07/18] let OnDirectKeyEvent find parents of ItemTemplated elements, give cmdpal the power to detect alts --- .../TerminalApp/AppActionHandlers.cpp | 48 ++++--------------- src/cascadia/TerminalApp/AppLogic.cpp | 7 +++ src/cascadia/TerminalApp/CommandPalette.cpp | 39 +++++++++++++-- src/cascadia/TerminalApp/CommandPalette.h | 3 ++ src/cascadia/TerminalApp/CommandPalette.idl | 3 +- 5 files changed, 56 insertions(+), 44 deletions(-) diff --git a/src/cascadia/TerminalApp/AppActionHandlers.cpp b/src/cascadia/TerminalApp/AppActionHandlers.cpp index d3842f3e201..5905f64eb27 100644 --- a/src/cascadia/TerminalApp/AppActionHandlers.cpp +++ b/src/cascadia/TerminalApp/AppActionHandlers.cpp @@ -80,26 +80,12 @@ namespace winrt::TerminalApp::implementation { if (_settings->GlobalSettings().UseTabSwitcher()) { - auto const ctrlDown = WI_IsFlagSet(CoreWindow::GetForCurrentThread().GetKeyState(winrt::Windows::System::VirtualKey::Control), CoreVirtualKeyStates::Down); - auto const altDown = WI_IsFlagSet(CoreWindow::GetForCurrentThread().GetKeyState(winrt::Windows::System::VirtualKey::Menu), CoreVirtualKeyStates::Down); - auto const shiftDown = WI_IsFlagSet(CoreWindow::GetForCurrentThread().GetKeyState(winrt::Windows::System::VirtualKey::Shift), CoreVirtualKeyStates::Down); - - // One or more of the modifiers should be pressed when invoking next/prev Tab. In priority order, choose one as the anchor. - // If none of the modifier keys were pressed while invoking next/prev Tab, TODO: idk wtf they're thinking so just do classic nT/pT - auto anchorKey = ctrlDown ? VirtualKey::Control : altDown ? VirtualKey::Menu : shiftDown ? VirtualKey::Shift : VirtualKey::None; - if (anchorKey == VirtualKey::None) - { - _SelectNextTab(true); - } - else - { - auto opt = _GetFocusedTabIndex(); - uint32_t startIdx = opt ? *opt : 0; - startIdx = (startIdx + _tabs.Size() + 1) % _tabs.Size(); + auto opt = _GetFocusedTabIndex(); + uint32_t startIdx = opt ? *opt : 0; + startIdx = (startIdx + _tabs.Size() + 1) % _tabs.Size(); - CommandPalette().EnableTabSwitcherMode(anchorKey, startIdx); - CommandPalette().Visibility(Visibility::Visible); - } + CommandPalette().EnableTabSwitcherMode(VirtualKey::Menu, startIdx); + CommandPalette().Visibility(Visibility::Visible); } else { @@ -115,26 +101,12 @@ namespace winrt::TerminalApp::implementation { if (_settings->GlobalSettings().UseTabSwitcher()) { - auto const ctrlDown = WI_IsFlagSet(CoreWindow::GetForCurrentThread().GetKeyState(winrt::Windows::System::VirtualKey::Control), CoreVirtualKeyStates::Down); - auto const altDown = WI_IsFlagSet(CoreWindow::GetForCurrentThread().GetKeyState(winrt::Windows::System::VirtualKey::Menu), CoreVirtualKeyStates::Down); - auto const shiftDown = WI_IsFlagSet(CoreWindow::GetForCurrentThread().GetKeyState(winrt::Windows::System::VirtualKey::Shift), CoreVirtualKeyStates::Down); - - // One or more of the modifiers should be pressed when invoking next/prev Tab. In priority order, choose one as the anchor. - // If none of the modifier keys were pressed while invoking next/prev Tab, TODO: idk wtf they're thinking so just do classic nT/pT - auto anchorKey = ctrlDown ? VirtualKey::Control : altDown ? VirtualKey::Menu : shiftDown ? VirtualKey::Shift : VirtualKey::None; - if (anchorKey == VirtualKey::None) - { - _SelectNextTab(false); - } - else - { - auto opt = _GetFocusedTabIndex(); - uint32_t startIdx = opt ? *opt : 0; - startIdx = (startIdx + _tabs.Size() - 1) % _tabs.Size(); + auto opt = _GetFocusedTabIndex(); + uint32_t startIdx = opt ? *opt : 0; + startIdx = (startIdx + _tabs.Size() - 1) % _tabs.Size(); - CommandPalette().EnableTabSwitcherMode(anchorKey, startIdx); - CommandPalette().Visibility(Visibility::Visible); - } + CommandPalette().EnableTabSwitcherMode(VirtualKey::Menu, startIdx); + CommandPalette().Visibility(Visibility::Visible); } else { diff --git a/src/cascadia/TerminalApp/AppLogic.cpp b/src/cascadia/TerminalApp/AppLogic.cpp index 9b6c3eddc77..ae902cb463b 100644 --- a/src/cascadia/TerminalApp/AppLogic.cpp +++ b/src/cascadia/TerminalApp/AppLogic.cpp @@ -937,6 +937,13 @@ namespace winrt::TerminalApp::implementation if (auto focusedElement{ focusedObject.try_as() }) { focusedObject = focusedElement.Parent(); + + // Parent() seems to return null when the focusedElement is created from an ItemTemplate. + // Use the VisualTreeHelper's GetParent as a fallback. + if (!focusedObject) + { + focusedObject = winrt::Windows::UI::Xaml::Media::VisualTreeHelper::GetParent(focusedElement); + } } else { diff --git a/src/cascadia/TerminalApp/CommandPalette.cpp b/src/cascadia/TerminalApp/CommandPalette.cpp index d8b8b9ef2ed..fbc1f69f769 100644 --- a/src/cascadia/TerminalApp/CommandPalette.cpp +++ b/src/cascadia/TerminalApp/CommandPalette.cpp @@ -7,6 +7,7 @@ #include "ActionArgs.h" #include "Command.h" +#include #include #include "CommandPalette.g.cpp" @@ -193,13 +194,43 @@ namespace winrt::TerminalApp::implementation } } + // Method Description: + // - Implements the Alt KeyUp handler + // Return value: + // - whether the key was handled + bool CommandPalette::OnDirectKeyEvent(const uint32_t vkey, const bool down) + { + auto handled = false; + if (_currentMode == CommandPaletteMode::TabSwitcherMode && + _anchorKey != VirtualKey::None) + { + if (vkey == VK_MENU && !down) + { + _anchorKeyUpHandler(); + handled = true; + } + } + return handled; + } + void CommandPalette::_keyUpHandler(IInspectable const& /*sender*/, Windows::UI::Xaml::Input::KeyRoutedEventArgs const& e) { - // Alt KeyUps are just not going to be detected unfortunately. if (_currentMode == CommandPaletteMode::TabSwitcherMode && - _anchorKey != VirtualKey::None && - e.OriginalKey() == _anchorKey) + _anchorKey != VirtualKey::None) + { + _anchorKeyUpHandler(); + e.Handled(true); + } + } + + void CommandPalette::_anchorKeyUpHandler() + { + auto const ctrlDown = WI_IsFlagSet(CoreWindow::GetForCurrentThread().GetKeyState(winrt::Windows::System::VirtualKey::Control), CoreVirtualKeyStates::Down); + auto const altDown = WI_IsFlagSet(CoreWindow::GetForCurrentThread().GetKeyState(winrt::Windows::System::VirtualKey::Menu), CoreVirtualKeyStates::Down); + auto const shiftDown = WI_IsFlagSet(CoreWindow::GetForCurrentThread().GetKeyState(winrt::Windows::System::VirtualKey::Shift), CoreVirtualKeyStates::Down); + + if (!ctrlDown && !altDown && !shiftDown) { if (const auto selectedItem = _filteredActionsView().SelectedItem()) { @@ -208,8 +239,6 @@ namespace winrt::TerminalApp::implementation _dispatchCommand(data); } } - - e.Handled(true); } } diff --git a/src/cascadia/TerminalApp/CommandPalette.h b/src/cascadia/TerminalApp/CommandPalette.h index f7bc5ba8f9f..4ae6b76138a 100644 --- a/src/cascadia/TerminalApp/CommandPalette.h +++ b/src/cascadia/TerminalApp/CommandPalette.h @@ -25,6 +25,8 @@ namespace winrt::TerminalApp::implementation void SetDispatch(const winrt::TerminalApp::ShortcutActionDispatch& dispatch); + bool OnDirectKeyEvent(const uint32_t vkey, const bool down); + // Tab Switcher void EnableTabSwitcherMode(const Windows::System::VirtualKey& anchorKey, const uint32_t startIdx); void OnTabsChanged(const Windows::Foundation::IInspectable& s, const Windows::Foundation::Collections::IVectorChangedEventArgs& e); @@ -74,6 +76,7 @@ namespace winrt::TerminalApp::implementation void UpdateTabIndices(const uint32_t startIdx); Windows::Foundation::Collections::IVector _allTabActions{ nullptr }; uint32_t _switcherStartIdx; + void _anchorKeyUpHandler(); winrt::Windows::UI::Xaml::Controls::ListView::SizeChanged_revoker _sizeChangedRevoker; diff --git a/src/cascadia/TerminalApp/CommandPalette.idl b/src/cascadia/TerminalApp/CommandPalette.idl index 8286077a4e4..82c78209ca5 100644 --- a/src/cascadia/TerminalApp/CommandPalette.idl +++ b/src/cascadia/TerminalApp/CommandPalette.idl @@ -2,10 +2,11 @@ // Licensed under the MIT license. import "../Command.idl"; +import "../IDirectKeyListener.idl"; namespace TerminalApp { - [default_interface] runtimeclass CommandPalette : Windows.UI.Xaml.Controls.UserControl, Windows.UI.Xaml.Data.INotifyPropertyChanged + [default_interface] runtimeclass CommandPalette : Windows.UI.Xaml.Controls.UserControl, Windows.UI.Xaml.Data.INotifyPropertyChanged, IDirectKeyListener { CommandPalette(); From c62bfb2dadc2b1b0f97937e489f64dc33377f5f1 Mon Sep 17 00:00:00 2001 From: Leon Liang Date: Mon, 17 Aug 2020 14:48:54 -0700 Subject: [PATCH 08/18] separate mode into tabswitch and tabsearch --- .../TerminalApp/AppActionHandlers.cpp | 6 +-- src/cascadia/TerminalApp/CommandPalette.cpp | 45 ++++++++++++------- src/cascadia/TerminalApp/CommandPalette.h | 7 +-- src/cascadia/TerminalApp/CommandPalette.idl | 2 +- 4 files changed, 37 insertions(+), 23 deletions(-) diff --git a/src/cascadia/TerminalApp/AppActionHandlers.cpp b/src/cascadia/TerminalApp/AppActionHandlers.cpp index 5905f64eb27..44d94759b56 100644 --- a/src/cascadia/TerminalApp/AppActionHandlers.cpp +++ b/src/cascadia/TerminalApp/AppActionHandlers.cpp @@ -84,7 +84,7 @@ namespace winrt::TerminalApp::implementation uint32_t startIdx = opt ? *opt : 0; startIdx = (startIdx + _tabs.Size() + 1) % _tabs.Size(); - CommandPalette().EnableTabSwitcherMode(VirtualKey::Menu, startIdx); + CommandPalette().EnableTabSwitcherMode(false, startIdx); CommandPalette().Visibility(Visibility::Visible); } else @@ -105,7 +105,7 @@ namespace winrt::TerminalApp::implementation uint32_t startIdx = opt ? *opt : 0; startIdx = (startIdx + _tabs.Size() - 1) % _tabs.Size(); - CommandPalette().EnableTabSwitcherMode(VirtualKey::Menu, startIdx); + CommandPalette().EnableTabSwitcherMode(false, startIdx); CommandPalette().Visibility(Visibility::Visible); } else @@ -487,7 +487,7 @@ namespace winrt::TerminalApp::implementation auto opt = _GetFocusedTabIndex(); uint32_t startIdx = opt ? *opt : 0; - CommandPalette().EnableTabSwitcherMode(VirtualKey::None, startIdx); + CommandPalette().EnableTabSwitcherMode(true, startIdx); CommandPalette().Visibility(Visibility::Visible); args.Handled(true); diff --git a/src/cascadia/TerminalApp/CommandPalette.cpp b/src/cascadia/TerminalApp/CommandPalette.cpp index fbc1f69f769..87a36389ca5 100644 --- a/src/cascadia/TerminalApp/CommandPalette.cpp +++ b/src/cascadia/TerminalApp/CommandPalette.cpp @@ -23,7 +23,6 @@ using namespace winrt::Windows::Foundation::Collections; namespace winrt::TerminalApp::implementation { CommandPalette::CommandPalette() : - _anchorKey{ VirtualKey::None }, _switcherStartIdx{ 0 } { InitializeComponent(); @@ -50,7 +49,7 @@ namespace winrt::TerminalApp::implementation RegisterPropertyChangedCallback(UIElement::VisibilityProperty(), [this](auto&&, auto&&) { if (Visibility() == Visibility::Visible) { - if (_currentMode == CommandPaletteMode::TabSwitcherMode && _anchorKey != VirtualKey::None) + if (_currentMode == CommandPaletteMode::TabSwitchMode) { _searchBox().Visibility(Visibility::Collapsed); _filteredActionsView().Focus(FocusState::Keyboard); @@ -84,7 +83,7 @@ namespace winrt::TerminalApp::implementation // when the ListView has been measured out and is ready, and we'll immediately // revoke the handler because we only needed to handle it once on initialization. _sizeChangedRevoker = _filteredActionsView().SizeChanged(winrt::auto_revoke, [this](auto /*s*/, auto /*e*/) { - if (_currentMode == CommandPaletteMode::TabSwitcherMode && _anchorKey != VirtualKey::None) + if (_currentMode == CommandPaletteMode::TabSwitchMode) { _filteredActionsView().Focus(FocusState::Keyboard); } @@ -124,9 +123,7 @@ namespace winrt::TerminalApp::implementation // Only give anchored tab switcher the ability to cycle through tabs with the tab button. // For unanchored mode, accessibility becomes an issue when we try to hijack tab since it's // a really widely used keyboard navigation key. - if (_currentMode == CommandPaletteMode::TabSwitcherMode && - key == VirtualKey::Tab && - _anchorKey != VirtualKey::None) + if (_currentMode == CommandPaletteMode::TabSwitchMode && key == VirtualKey::Tab) { auto const state = CoreWindow::GetForCurrentThread().GetKeyState(winrt::Windows::System::VirtualKey::Shift); if (WI_IsFlagSet(state, CoreVirtualKeyStates::Down)) @@ -201,8 +198,7 @@ namespace winrt::TerminalApp::implementation bool CommandPalette::OnDirectKeyEvent(const uint32_t vkey, const bool down) { auto handled = false; - if (_currentMode == CommandPaletteMode::TabSwitcherMode && - _anchorKey != VirtualKey::None) + if (_currentMode == CommandPaletteMode::TabSwitchMode) { if (vkey == VK_MENU && !down) { @@ -216,14 +212,21 @@ namespace winrt::TerminalApp::implementation void CommandPalette::_keyUpHandler(IInspectable const& /*sender*/, Windows::UI::Xaml::Input::KeyRoutedEventArgs const& e) { - if (_currentMode == CommandPaletteMode::TabSwitcherMode && - _anchorKey != VirtualKey::None) + if (_currentMode == CommandPaletteMode::TabSwitchMode) { _anchorKeyUpHandler(); e.Handled(true); } } + // Method Description: + // - Handles anchor key ups during TabSwitchMode. + // We assume that at least one modifier key should be held down in order to "anchor" + // the ATS UI in place. So, this function is called by key up handlers to check if + // any modifiers are still held down, and if not, dispatch the tab switch action and + // close the ATS. + // Return value: + // - void CommandPalette::_anchorKeyUpHandler() { auto const ctrlDown = WI_IsFlagSet(CoreWindow::GetForCurrentThread().GetKeyState(winrt::Windows::System::VirtualKey::Control), CoreVirtualKeyStates::Down); @@ -299,7 +302,8 @@ namespace winrt::TerminalApp::implementation { case CommandPaletteMode::ActionMode: return _allCommands; - case CommandPaletteMode::TabSwitcherMode: + case CommandPaletteMode::TabSearchMode: + case CommandPaletteMode::TabSwitchMode: return _allTabActions; default: return _allCommands; @@ -412,7 +416,8 @@ namespace winrt::TerminalApp::implementation // whenever _switchToMode is called. switch (_currentMode) { - case CommandPaletteMode::TabSwitcherMode: + case CommandPaletteMode::TabSearchMode: + case CommandPaletteMode::TabSwitchMode: { SearchBoxText(RS_(L"TabSwitcher_SearchBoxText")); NoMatchesText(RS_(L"TabSwitcher_NoMatchesText")); @@ -487,7 +492,7 @@ namespace winrt::TerminalApp::implementation { // If TabSwitcherMode, just add all as is. We don't want // them to be sorted alphabetically. - if (_currentMode == CommandPaletteMode::TabSwitcherMode) + if (_currentMode == CommandPaletteMode::TabSearchMode || _currentMode == CommandPaletteMode::TabSwitchMode) { for (auto action : commandsToFilter) { @@ -851,11 +856,19 @@ namespace winrt::TerminalApp::implementation } } - void CommandPalette::EnableTabSwitcherMode(const VirtualKey& anchorKey, const uint32_t startIdx) + void CommandPalette::EnableTabSwitcherMode(const bool searchMode, const uint32_t startIdx) { _switcherStartIdx = startIdx; - _anchorKey = anchorKey; - _switchToMode(CommandPaletteMode::TabSwitcherMode); + + if (searchMode) + { + _switchToMode(CommandPaletteMode::TabSearchMode); + } + else + { + _switchToMode(CommandPaletteMode::TabSwitchMode); + } + _updateFilteredActions(); } } diff --git a/src/cascadia/TerminalApp/CommandPalette.h b/src/cascadia/TerminalApp/CommandPalette.h index 4ae6b76138a..4815c67b1d9 100644 --- a/src/cascadia/TerminalApp/CommandPalette.h +++ b/src/cascadia/TerminalApp/CommandPalette.h @@ -11,7 +11,8 @@ namespace winrt::TerminalApp::implementation enum class CommandPaletteMode { ActionMode = 0, - TabSwitcherMode + TabSearchMode, + TabSwitchMode }; struct CommandPalette : CommandPaletteT @@ -28,7 +29,7 @@ namespace winrt::TerminalApp::implementation bool OnDirectKeyEvent(const uint32_t vkey, const bool down); // Tab Switcher - void EnableTabSwitcherMode(const Windows::System::VirtualKey& anchorKey, const uint32_t startIdx); + void EnableTabSwitcherMode(const bool searchMode, const uint32_t startIdx); void OnTabsChanged(const Windows::Foundation::IInspectable& s, const Windows::Foundation::Collections::IVectorChangedEventArgs& e); WINRT_CALLBACK(PropertyChanged, Windows::UI::Xaml::Data::PropertyChangedEventHandler); @@ -71,7 +72,7 @@ namespace winrt::TerminalApp::implementation void _switchToMode(CommandPaletteMode mode); // Tab Switcher - winrt::Windows::System::VirtualKey _anchorKey; + bool _anchoredMode; void GenerateCommandForTab(const uint32_t idx, bool inserted, winrt::TerminalApp::Tab& tab); void UpdateTabIndices(const uint32_t startIdx); Windows::Foundation::Collections::IVector _allTabActions{ nullptr }; diff --git a/src/cascadia/TerminalApp/CommandPalette.idl b/src/cascadia/TerminalApp/CommandPalette.idl index 82c78209ca5..3a0f5ac048d 100644 --- a/src/cascadia/TerminalApp/CommandPalette.idl +++ b/src/cascadia/TerminalApp/CommandPalette.idl @@ -21,7 +21,7 @@ namespace TerminalApp void SetDispatch(ShortcutActionDispatch dispatch); - void EnableTabSwitcherMode(Windows.System.VirtualKey anchorKey, UInt32 startIdx); + void EnableTabSwitcherMode(Boolean searchMode, UInt32 startIdx); void OnTabsChanged(IInspectable s, Windows.Foundation.Collections.IVectorChangedEventArgs e); } } From 433ec748f9fb0cc1ae0c71b5ff52bc3b91779ed2 Mon Sep 17 00:00:00 2001 From: Leon Liang Date: Mon, 17 Aug 2020 15:41:43 -0700 Subject: [PATCH 09/18] cue don't let your dreams be dreams meme --- .../TerminalApp/AppActionHandlers.cpp | 10 +++++++ src/cascadia/TerminalApp/CommandPalette.cpp | 29 ++++++++++++++++++- src/cascadia/TerminalApp/CommandPalette.h | 10 +++++-- src/cascadia/TerminalApp/CommandPalette.idl | 3 ++ src/cascadia/TerminalApp/TerminalPage.cpp | 1 + 5 files changed, 49 insertions(+), 4 deletions(-) diff --git a/src/cascadia/TerminalApp/AppActionHandlers.cpp b/src/cascadia/TerminalApp/AppActionHandlers.cpp index 511703cc5f8..76bb6b04c11 100644 --- a/src/cascadia/TerminalApp/AppActionHandlers.cpp +++ b/src/cascadia/TerminalApp/AppActionHandlers.cpp @@ -80,6 +80,11 @@ namespace winrt::TerminalApp::implementation { if (_settings->GlobalSettings().UseTabSwitcher()) { + if (CommandPalette().Visibility() == Visibility::Visible) + { + CommandPalette()._selectNextItem(true); + } + auto opt = _GetFocusedTabIndex(); uint32_t startIdx = opt ? *opt : 0; startIdx = (startIdx + _tabs.Size() + 1) % _tabs.Size(); @@ -101,6 +106,11 @@ namespace winrt::TerminalApp::implementation { if (_settings->GlobalSettings().UseTabSwitcher()) { + if (CommandPalette().Visibility() == Visibility::Visible) + { + CommandPalette()._selectNextItem(false); + } + auto opt = _GetFocusedTabIndex(); uint32_t startIdx = opt ? *opt : 0; startIdx = (startIdx + _tabs.Size() - 1) % _tabs.Size(); diff --git a/src/cascadia/TerminalApp/CommandPalette.cpp b/src/cascadia/TerminalApp/CommandPalette.cpp index fd22242e6e1..1d101b039b1 100644 --- a/src/cascadia/TerminalApp/CommandPalette.cpp +++ b/src/cascadia/TerminalApp/CommandPalette.cpp @@ -154,6 +154,28 @@ namespace winrt::TerminalApp::implementation Windows::UI::Xaml::Input::KeyRoutedEventArgs const& e) { auto key = e.OriginalKey(); + const auto vkey = ::gsl::narrow_cast(e.OriginalKey()); + + // Since I'm not sure if I want to open up all key downs to keybindings, I'll limit it to + // happen only during TabSwitch mode. + if (_currentMode == CommandPaletteMode::TabSwitchMode) + { + auto const ctrlDown = WI_IsFlagSet(CoreWindow::GetForCurrentThread().GetKeyState(winrt::Windows::System::VirtualKey::Control), CoreVirtualKeyStates::Down); + auto const altDown = WI_IsFlagSet(CoreWindow::GetForCurrentThread().GetKeyState(winrt::Windows::System::VirtualKey::Menu), CoreVirtualKeyStates::Down); + auto const shiftDown = WI_IsFlagSet(CoreWindow::GetForCurrentThread().GetKeyState(winrt::Windows::System::VirtualKey::Shift), CoreVirtualKeyStates::Down); + + auto success = _bindings.TryKeyChord({ + ctrlDown, + altDown, + shiftDown, + vkey, + }); + + if (success) + { + e.Handled(true); + } + } if (key == VirtualKey::Up) { @@ -198,7 +220,7 @@ namespace winrt::TerminalApp::implementation // - Implements the Alt KeyUp handler // Return value: // - whether the key was handled - bool CommandPalette::OnDirectKeyEvent(const uint32_t vkey, const bool down) + bool CommandPalette::OnDirectKeyEvent(const uint32_t vkey, const uint8_t /*scanCode*/, const bool down) { auto handled = false; if (_currentMode == CommandPaletteMode::TabSwitchMode) @@ -248,6 +270,11 @@ namespace winrt::TerminalApp::implementation } } + void CommandPalette::SetBindings(Microsoft::Terminal::TerminalControl::IKeyBindings bindings) + { + _bindings = bindings; + } + // Method Description: // - This event is triggered when someone clicks anywhere in the bounds of // the window that's _not_ the command palette UI. When that happens, diff --git a/src/cascadia/TerminalApp/CommandPalette.h b/src/cascadia/TerminalApp/CommandPalette.h index 692409134c0..99b8f6086b5 100644 --- a/src/cascadia/TerminalApp/CommandPalette.h +++ b/src/cascadia/TerminalApp/CommandPalette.h @@ -22,11 +22,15 @@ namespace winrt::TerminalApp::implementation Windows::Foundation::Collections::IObservableVector FilteredActions(); void SetCommands(Windows::Foundation::Collections::IVector const& actions); + void SetBindings(Microsoft::Terminal::TerminalControl::IKeyBindings bindings); + void EnableCommandPaletteMode(); void SetDispatch(const winrt::TerminalApp::ShortcutActionDispatch& dispatch); - bool OnDirectKeyEvent(const uint32_t vkey, const bool down); + bool OnDirectKeyEvent(const uint32_t vkey, const uint8_t scanCode, const bool down); + + void _selectNextItem(const bool moveDown); // Tab Switcher void EnableTabSwitcherMode(const bool searchMode, const uint32_t startIdx); @@ -65,8 +69,6 @@ namespace winrt::TerminalApp::implementation void _listItemClicked(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::Controls::ItemClickEventArgs const& e); - void _selectNextItem(const bool moveDown); - void _updateFilteredActions(); std::vector _collectFilteredActions(); @@ -77,6 +79,8 @@ namespace winrt::TerminalApp::implementation CommandPaletteMode _currentMode; void _switchToMode(CommandPaletteMode mode); + Microsoft::Terminal::TerminalControl::IKeyBindings _bindings; + // Tab Switcher bool _anchoredMode; void GenerateCommandForTab(const uint32_t idx, bool inserted, winrt::TerminalApp::Tab& tab); diff --git a/src/cascadia/TerminalApp/CommandPalette.idl b/src/cascadia/TerminalApp/CommandPalette.idl index 3a0f5ac048d..d61ff8e02f0 100644 --- a/src/cascadia/TerminalApp/CommandPalette.idl +++ b/src/cascadia/TerminalApp/CommandPalette.idl @@ -17,8 +17,11 @@ namespace TerminalApp Windows.Foundation.Collections.IObservableVector FilteredActions { get; }; void SetCommands(Windows.Foundation.Collections.IVector actions); + void SetBindings(Microsoft.Terminal.TerminalControl.IKeyBindings bindings); void EnableCommandPaletteMode(); + void _selectNextItem(Boolean moveDown); + void SetDispatch(ShortcutActionDispatch dispatch); void EnableTabSwitcherMode(Boolean searchMode, UInt32 startIdx); diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index cd0b4945fe8..231ba82ba3e 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -119,6 +119,7 @@ namespace winrt::TerminalApp::implementation if (auto page{ weakThis.get() }) { _UpdateCommandsForPalette(); + page->CommandPalette().SetBindings(_settings->GetKeybindings()); } } From 3799be29c5c745b1ce48026b5b533f2343d91913 Mon Sep 17 00:00:00 2001 From: Leon Liang Date: Mon, 17 Aug 2020 15:51:13 -0700 Subject: [PATCH 10/18] a bit more cleanup --- .../TerminalApp/AppActionHandlers.cpp | 4 +- src/cascadia/TerminalApp/CommandPalette.cpp | 68 ++++++++++--------- src/cascadia/TerminalApp/CommandPalette.h | 4 +- src/cascadia/TerminalApp/CommandPalette.idl | 4 +- src/cascadia/TerminalApp/TerminalPage.cpp | 2 +- 5 files changed, 42 insertions(+), 40 deletions(-) diff --git a/src/cascadia/TerminalApp/AppActionHandlers.cpp b/src/cascadia/TerminalApp/AppActionHandlers.cpp index 76bb6b04c11..8019b6c3b74 100644 --- a/src/cascadia/TerminalApp/AppActionHandlers.cpp +++ b/src/cascadia/TerminalApp/AppActionHandlers.cpp @@ -82,7 +82,7 @@ namespace winrt::TerminalApp::implementation { if (CommandPalette().Visibility() == Visibility::Visible) { - CommandPalette()._selectNextItem(true); + CommandPalette().SelectNextItem(true); } auto opt = _GetFocusedTabIndex(); @@ -108,7 +108,7 @@ namespace winrt::TerminalApp::implementation { if (CommandPalette().Visibility() == Visibility::Visible) { - CommandPalette()._selectNextItem(false); + CommandPalette().SelectNextItem(false); } auto opt = _GetFocusedTabIndex(); diff --git a/src/cascadia/TerminalApp/CommandPalette.cpp b/src/cascadia/TerminalApp/CommandPalette.cpp index 1d101b039b1..1123c891070 100644 --- a/src/cascadia/TerminalApp/CommandPalette.cpp +++ b/src/cascadia/TerminalApp/CommandPalette.cpp @@ -102,7 +102,7 @@ namespace winrt::TerminalApp::implementation // list. Otherwise, we're attempting to move to the previous. // Return Value: // - - void CommandPalette::_selectNextItem(const bool moveDown) + void CommandPalette::SelectNextItem(const bool moveDown) { const auto selected = _filteredActionsView().SelectedIndex(); const int numItems = ::base::saturated_cast(_filteredActionsView().Items().Size()); @@ -131,12 +131,12 @@ namespace winrt::TerminalApp::implementation auto const state = CoreWindow::GetForCurrentThread().GetKeyState(winrt::Windows::System::VirtualKey::Shift); if (WI_IsFlagSet(state, CoreVirtualKeyStates::Down)) { - _selectNextItem(false); + SelectNextItem(false); e.Handled(true); } else { - _selectNextItem(true); + SelectNextItem(true); e.Handled(true); } } @@ -154,39 +154,17 @@ namespace winrt::TerminalApp::implementation Windows::UI::Xaml::Input::KeyRoutedEventArgs const& e) { auto key = e.OriginalKey(); - const auto vkey = ::gsl::narrow_cast(e.OriginalKey()); - - // Since I'm not sure if I want to open up all key downs to keybindings, I'll limit it to - // happen only during TabSwitch mode. - if (_currentMode == CommandPaletteMode::TabSwitchMode) - { - auto const ctrlDown = WI_IsFlagSet(CoreWindow::GetForCurrentThread().GetKeyState(winrt::Windows::System::VirtualKey::Control), CoreVirtualKeyStates::Down); - auto const altDown = WI_IsFlagSet(CoreWindow::GetForCurrentThread().GetKeyState(winrt::Windows::System::VirtualKey::Menu), CoreVirtualKeyStates::Down); - auto const shiftDown = WI_IsFlagSet(CoreWindow::GetForCurrentThread().GetKeyState(winrt::Windows::System::VirtualKey::Shift), CoreVirtualKeyStates::Down); - - auto success = _bindings.TryKeyChord({ - ctrlDown, - altDown, - shiftDown, - vkey, - }); - - if (success) - { - e.Handled(true); - } - } if (key == VirtualKey::Up) { // Action Mode: Move focus to the next item in the list. - _selectNextItem(false); + SelectNextItem(false); e.Handled(true); } else if (key == VirtualKey::Down) { // Action Mode: Move focus to the previous item in the list. - _selectNextItem(true); + SelectNextItem(true); e.Handled(true); } else if (key == VirtualKey::Enter) @@ -214,10 +192,34 @@ namespace winrt::TerminalApp::implementation e.Handled(true); } + else + { + const auto vkey = ::gsl::narrow_cast(e.OriginalKey()); + + // In the interest of not telling all modes to check for keybindings, limit to TabSwitch mode for now. + if (_currentMode == CommandPaletteMode::TabSwitchMode) + { + auto const ctrlDown = WI_IsFlagSet(CoreWindow::GetForCurrentThread().GetKeyState(winrt::Windows::System::VirtualKey::Control), CoreVirtualKeyStates::Down); + auto const altDown = WI_IsFlagSet(CoreWindow::GetForCurrentThread().GetKeyState(winrt::Windows::System::VirtualKey::Menu), CoreVirtualKeyStates::Down); + auto const shiftDown = WI_IsFlagSet(CoreWindow::GetForCurrentThread().GetKeyState(winrt::Windows::System::VirtualKey::Shift), CoreVirtualKeyStates::Down); + + auto success = _bindings.TryKeyChord({ + ctrlDown, + altDown, + shiftDown, + vkey, + }); + + if (success) + { + e.Handled(true); + } + } + } } // Method Description: - // - Implements the Alt KeyUp handler + // - Implements the Alt handler // Return value: // - whether the key was handled bool CommandPalette::OnDirectKeyEvent(const uint32_t vkey, const uint8_t /*scanCode*/, const bool down) @@ -270,11 +272,6 @@ namespace winrt::TerminalApp::implementation } } - void CommandPalette::SetBindings(Microsoft::Terminal::TerminalControl::IKeyBindings bindings) - { - _bindings = bindings; - } - // Method Description: // - This event is triggered when someone clicks anywhere in the bounds of // the window that's _not_ the command palette UI. When that happens, @@ -463,6 +460,11 @@ namespace winrt::TerminalApp::implementation return _filteredActions; } + void CommandPalette::SetKeyBindings(Microsoft::Terminal::TerminalControl::IKeyBindings bindings) + { + _bindings = bindings; + } + void CommandPalette::SetCommands(Collections::IVector const& actions) { _allCommands = actions; diff --git a/src/cascadia/TerminalApp/CommandPalette.h b/src/cascadia/TerminalApp/CommandPalette.h index 99b8f6086b5..7a7ee507307 100644 --- a/src/cascadia/TerminalApp/CommandPalette.h +++ b/src/cascadia/TerminalApp/CommandPalette.h @@ -22,7 +22,7 @@ namespace winrt::TerminalApp::implementation Windows::Foundation::Collections::IObservableVector FilteredActions(); void SetCommands(Windows::Foundation::Collections::IVector const& actions); - void SetBindings(Microsoft::Terminal::TerminalControl::IKeyBindings bindings); + void SetKeyBindings(Microsoft::Terminal::TerminalControl::IKeyBindings bindings); void EnableCommandPaletteMode(); @@ -30,7 +30,7 @@ namespace winrt::TerminalApp::implementation bool OnDirectKeyEvent(const uint32_t vkey, const uint8_t scanCode, const bool down); - void _selectNextItem(const bool moveDown); + void SelectNextItem(const bool moveDown); // Tab Switcher void EnableTabSwitcherMode(const bool searchMode, const uint32_t startIdx); diff --git a/src/cascadia/TerminalApp/CommandPalette.idl b/src/cascadia/TerminalApp/CommandPalette.idl index d61ff8e02f0..c591786006e 100644 --- a/src/cascadia/TerminalApp/CommandPalette.idl +++ b/src/cascadia/TerminalApp/CommandPalette.idl @@ -17,10 +17,10 @@ namespace TerminalApp Windows.Foundation.Collections.IObservableVector FilteredActions { get; }; void SetCommands(Windows.Foundation.Collections.IVector actions); - void SetBindings(Microsoft.Terminal.TerminalControl.IKeyBindings bindings); + void SetKeyBindings(Microsoft.Terminal.TerminalControl.IKeyBindings bindings); void EnableCommandPaletteMode(); - void _selectNextItem(Boolean moveDown); + void SelectNextItem(Boolean moveDown); void SetDispatch(ShortcutActionDispatch dispatch); diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index 231ba82ba3e..1d1b48aaf9f 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -119,7 +119,7 @@ namespace winrt::TerminalApp::implementation if (auto page{ weakThis.get() }) { _UpdateCommandsForPalette(); - page->CommandPalette().SetBindings(_settings->GetKeybindings()); + page->CommandPalette().SetKeyBindings(_settings->GetKeybindings()); } } From 9306f0dd47580a1815b9a7b39596e42be383e6b1 Mon Sep 17 00:00:00 2001 From: Leon Liang Date: Mon, 17 Aug 2020 16:06:30 -0700 Subject: [PATCH 11/18] schema updated --- doc/cascadia/profiles.schema.json | 19 +------------------ src/cascadia/TerminalApp/CommandPalette.h | 1 - 2 files changed, 1 insertion(+), 19 deletions(-) diff --git a/doc/cascadia/profiles.schema.json b/doc/cascadia/profiles.schema.json index 6456d452c13..6a7579532fb 100644 --- a/doc/cascadia/profiles.schema.json +++ b/doc/cascadia/profiles.schema.json @@ -68,7 +68,7 @@ "wt", "closeOtherTabs", "closeTabsAfter", - "tabSwitcher", + "tabSearch", "unbound" ], "type": "string" @@ -422,22 +422,6 @@ ], "required": [ "index" ] }, - "TabSwitcherAction": { - "description": "Arguments corresponding to a Tab Switcher Action", - "allOf": [ - { "$ref": "#/definitions/ShortcutAction" }, - { - "properties": { - "action": { "type": "string", "pattern": "tabSwitcher" }, - "anchorKey": { - "$ref": "#/definitions/AnchorKey", - "default": null, - "description": "If provided, the tab switcher will stay open as long as the anchor key is held down. The anchor key should be part of the keybinding that opens the switcher." - } - } - } - ] - }, "Keybinding": { "additionalProperties": false, "properties": { @@ -459,7 +443,6 @@ { "$ref": "#/definitions/WtAction" }, { "$ref": "#/definitions/CloseOtherTabsAction" }, { "$ref": "#/definitions/CloseTabsAfterAction" }, - { "$ref": "#/definitions/TabSwitcherAction" }, { "type": "null" } ] }, diff --git a/src/cascadia/TerminalApp/CommandPalette.h b/src/cascadia/TerminalApp/CommandPalette.h index 7a7ee507307..966b879c4d3 100644 --- a/src/cascadia/TerminalApp/CommandPalette.h +++ b/src/cascadia/TerminalApp/CommandPalette.h @@ -82,7 +82,6 @@ namespace winrt::TerminalApp::implementation Microsoft::Terminal::TerminalControl::IKeyBindings _bindings; // Tab Switcher - bool _anchoredMode; void GenerateCommandForTab(const uint32_t idx, bool inserted, winrt::TerminalApp::Tab& tab); void UpdateTabIndices(const uint32_t startIdx); Windows::Foundation::Collections::IVector _allTabActions{ nullptr }; From c293055274d9fc68f2778400c47cb46136e1538b Mon Sep 17 00:00:00 2001 From: Leon Liang Date: Tue, 18 Aug 2020 15:26:38 -0700 Subject: [PATCH 12/18] a whole lotta thinking resulting in just one line changed --- src/cascadia/TerminalApp/AppActionHandlers.cpp | 1 - src/cascadia/TerminalApp/CommandPalette.cpp | 9 ++++++--- src/cascadia/TerminalApp/TerminalPage.cpp | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/cascadia/TerminalApp/AppActionHandlers.cpp b/src/cascadia/TerminalApp/AppActionHandlers.cpp index 8019b6c3b74..ddf23c1e5d0 100644 --- a/src/cascadia/TerminalApp/AppActionHandlers.cpp +++ b/src/cascadia/TerminalApp/AppActionHandlers.cpp @@ -97,7 +97,6 @@ namespace winrt::TerminalApp::implementation _SelectNextTab(true); } - args.Handled(true); } diff --git a/src/cascadia/TerminalApp/CommandPalette.cpp b/src/cascadia/TerminalApp/CommandPalette.cpp index 1123c891070..f8f3cad7901 100644 --- a/src/cascadia/TerminalApp/CommandPalette.cpp +++ b/src/cascadia/TerminalApp/CommandPalette.cpp @@ -57,6 +57,10 @@ namespace winrt::TerminalApp::implementation _filteredActionsView().Focus(FocusState::Keyboard); _filteredActionsView().SelectedIndex(_switcherStartIdx); _filteredActionsView().ScrollIntoView(_filteredActionsView().SelectedItem()); + + // Do this right after becoming visible so we can quickly catch scenarios where + // modifiers aren't held down (e.g. cmdpal invocation). + _anchorKeyUpHandler(); } else { @@ -249,9 +253,8 @@ namespace winrt::TerminalApp::implementation // Method Description: // - Handles anchor key ups during TabSwitchMode. // We assume that at least one modifier key should be held down in order to "anchor" - // the ATS UI in place. So, this function is called by key up handlers to check if - // any modifiers are still held down, and if not, dispatch the tab switch action and - // close the ATS. + // the ATS UI in place. So this function is called to check if any modifiers are + // still held down, and if not, dispatch the selected tab action and close the ATS. // Return value: // - void CommandPalette::_anchorKeyUpHandler() diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index 1d1b48aaf9f..5eaad3ccd34 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -119,7 +119,7 @@ namespace winrt::TerminalApp::implementation if (auto page{ weakThis.get() }) { _UpdateCommandsForPalette(); - page->CommandPalette().SetKeyBindings(_settings->GetKeybindings()); + CommandPalette().SetKeyBindings(_settings->GetKeybindings()); } } From b43342e39eb7ffe39f3de3a6924c726d8abe35c1 Mon Sep 17 00:00:00 2001 From: Leon Liang Date: Tue, 18 Aug 2020 15:30:32 -0700 Subject: [PATCH 13/18] i didn't realize i was in the spelling bee --- src/cascadia/TerminalApp/CommandPalette.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cascadia/TerminalApp/CommandPalette.cpp b/src/cascadia/TerminalApp/CommandPalette.cpp index f8f3cad7901..639f71f5ec5 100644 --- a/src/cascadia/TerminalApp/CommandPalette.cpp +++ b/src/cascadia/TerminalApp/CommandPalette.cpp @@ -59,7 +59,7 @@ namespace winrt::TerminalApp::implementation _filteredActionsView().ScrollIntoView(_filteredActionsView().SelectedItem()); // Do this right after becoming visible so we can quickly catch scenarios where - // modifiers aren't held down (e.g. cmdpal invocation). + // modifiers aren't held down (e.g. command palette invocation). _anchorKeyUpHandler(); } else From ebff42c92013c36f581f3da892a3332a52dc34bc Mon Sep 17 00:00:00 2001 From: Leon Liang Date: Wed, 19 Aug 2020 11:18:47 -0700 Subject: [PATCH 14/18] removing setting from control --- src/cascadia/TerminalApp/GlobalAppSettings.cpp | 1 - src/cascadia/TerminalApp/TerminalSettings.h | 2 -- src/cascadia/TerminalControl/IControlSettings.idl | 2 -- 3 files changed, 5 deletions(-) diff --git a/src/cascadia/TerminalApp/GlobalAppSettings.cpp b/src/cascadia/TerminalApp/GlobalAppSettings.cpp index 231c081ed7f..999aed5fbad 100644 --- a/src/cascadia/TerminalApp/GlobalAppSettings.cpp +++ b/src/cascadia/TerminalApp/GlobalAppSettings.cpp @@ -118,7 +118,6 @@ void GlobalAppSettings::ApplyToSettings(TerminalSettings& settings) const noexce settings.ForceFullRepaintRendering(_ForceFullRepaintRendering); settings.SoftwareRendering(_SoftwareRendering); settings.ForceVTInput(_ForceVTInput); - settings.UseTabSwitcher(_UseTabSwitcher); } // Method Description: diff --git a/src/cascadia/TerminalApp/TerminalSettings.h b/src/cascadia/TerminalApp/TerminalSettings.h index b9c16d91655..53a4ab3201d 100644 --- a/src/cascadia/TerminalApp/TerminalSettings.h +++ b/src/cascadia/TerminalApp/TerminalSettings.h @@ -97,8 +97,6 @@ namespace winrt::TerminalApp::implementation GETSET_PROPERTY(bool, SoftwareRendering, false); GETSET_PROPERTY(bool, ForceVTInput, false); - GETSET_PROPERTY(bool, UseTabSwitcher, false); - #pragma warning(pop) private: diff --git a/src/cascadia/TerminalControl/IControlSettings.idl b/src/cascadia/TerminalControl/IControlSettings.idl index 8d5645db26c..2f140a0a3f8 100644 --- a/src/cascadia/TerminalControl/IControlSettings.idl +++ b/src/cascadia/TerminalControl/IControlSettings.idl @@ -57,7 +57,5 @@ namespace Microsoft.Terminal.TerminalControl Boolean RetroTerminalEffect; Boolean ForceFullRepaintRendering; Boolean SoftwareRendering; - - Boolean UseTabSwitcher; }; } From c74f29c3dfaf61699b1ee6425d37ce5fd276b1fd Mon Sep 17 00:00:00 2001 From: Leon Liang Date: Wed, 19 Aug 2020 13:29:43 -0700 Subject: [PATCH 15/18] might as well move this here, it's a bit cleaner --- .../TerminalApp/AppActionHandlers.cpp | 40 +------------------ src/cascadia/TerminalApp/TerminalPage.cpp | 16 +++++++- src/cascadia/TerminalApp/defaults.json | 2 +- 3 files changed, 18 insertions(+), 40 deletions(-) diff --git a/src/cascadia/TerminalApp/AppActionHandlers.cpp b/src/cascadia/TerminalApp/AppActionHandlers.cpp index ddf23c1e5d0..ce462029708 100644 --- a/src/cascadia/TerminalApp/AppActionHandlers.cpp +++ b/src/cascadia/TerminalApp/AppActionHandlers.cpp @@ -78,50 +78,14 @@ namespace winrt::TerminalApp::implementation void TerminalPage::_HandleNextTab(const IInspectable& /*sender*/, const TerminalApp::ActionEventArgs& args) { - if (_settings->GlobalSettings().UseTabSwitcher()) - { - if (CommandPalette().Visibility() == Visibility::Visible) - { - CommandPalette().SelectNextItem(true); - } - - auto opt = _GetFocusedTabIndex(); - uint32_t startIdx = opt ? *opt : 0; - startIdx = (startIdx + _tabs.Size() + 1) % _tabs.Size(); - - CommandPalette().EnableTabSwitcherMode(false, startIdx); - CommandPalette().Visibility(Visibility::Visible); - } - else - { - _SelectNextTab(true); - } - + _SelectNextTab(true); args.Handled(true); } void TerminalPage::_HandlePrevTab(const IInspectable& /*sender*/, const TerminalApp::ActionEventArgs& args) { - if (_settings->GlobalSettings().UseTabSwitcher()) - { - if (CommandPalette().Visibility() == Visibility::Visible) - { - CommandPalette().SelectNextItem(false); - } - - auto opt = _GetFocusedTabIndex(); - uint32_t startIdx = opt ? *opt : 0; - startIdx = (startIdx + _tabs.Size() - 1) % _tabs.Size(); - - CommandPalette().EnableTabSwitcherMode(false, startIdx); - CommandPalette().Visibility(Visibility::Visible); - } - else - { - _SelectNextTab(false); - } - + _SelectNextTab(false); args.Handled(true); } diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index 1273970b224..1cf6b177b15 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -1203,7 +1203,21 @@ namespace winrt::TerminalApp::implementation // we clamp the values to the range [0, tabCount) while still supporting moving // leftward from 0 to tabCount - 1. const auto newTabIndex = ((tabCount + *index + (bMoveRight ? 1 : -1)) % tabCount); - _SelectTab(newTabIndex); + + if (_settings->GlobalSettings().UseTabSwitcher()) + { + if (CommandPalette().Visibility() == Visibility::Visible) + { + CommandPalette().SelectNextItem(bMoveRight); + } + + CommandPalette().EnableTabSwitcherMode(false, newTabIndex); + CommandPalette().Visibility(Visibility::Visible); + } + else + { + _SelectTab(newTabIndex); + } } } diff --git a/src/cascadia/TerminalApp/defaults.json b/src/cascadia/TerminalApp/defaults.json index 028a65f9575..dab42625919 100644 --- a/src/cascadia/TerminalApp/defaults.json +++ b/src/cascadia/TerminalApp/defaults.json @@ -18,7 +18,7 @@ "showTabsInTitlebar": true, "showTerminalTitleInTitlebar": true, "tabWidthMode": "equal", - "useTabSwitcher": false, + "useTabSwitcher": true, // Miscellaneous "confirmCloseAllTabs": true, From 5f9a25f36e286d89cc42fbe004028015abe39eaf Mon Sep 17 00:00:00 2001 From: Leon Liang Date: Wed, 19 Aug 2020 13:59:44 -0700 Subject: [PATCH 16/18] value or Co-authored-by: Dustin L. Howett --- src/cascadia/TerminalApp/AppActionHandlers.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cascadia/TerminalApp/AppActionHandlers.cpp b/src/cascadia/TerminalApp/AppActionHandlers.cpp index ce462029708..8b4f4c6b0e1 100644 --- a/src/cascadia/TerminalApp/AppActionHandlers.cpp +++ b/src/cascadia/TerminalApp/AppActionHandlers.cpp @@ -460,7 +460,7 @@ namespace winrt::TerminalApp::implementation const TerminalApp::ActionEventArgs& args) { auto opt = _GetFocusedTabIndex(); - uint32_t startIdx = opt ? *opt : 0; + uint32_t startIdx = opt.value_or(0); CommandPalette().EnableTabSwitcherMode(true, startIdx); CommandPalette().Visibility(Visibility::Visible); From 1553354f1ef9233c75bdb7bdef38ebf9adedacdf Mon Sep 17 00:00:00 2001 From: Leon Liang Date: Thu, 20 Aug 2020 16:25:21 -0700 Subject: [PATCH 17/18] pr updates --- doc/cascadia/profiles.schema.json | 5 +++++ src/cascadia/TerminalApp/CommandPalette.cpp | 1 - src/cascadia/TerminalApp/Resources/en-US/Resources.resw | 2 +- src/cascadia/TerminalApp/lib/pch.h | 2 ++ 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/doc/cascadia/profiles.schema.json b/doc/cascadia/profiles.schema.json index b3c1edfd591..b815a330221 100644 --- a/doc/cascadia/profiles.schema.json +++ b/doc/cascadia/profiles.schema.json @@ -613,6 +613,11 @@ "default": true, "description": "When set to \"true\" closing a window with multiple tabs open will require confirmation. When set to \"false\", the confirmation dialog will not appear.", "type": "boolean" + }, + "useTabSwitcher": { + "default": true, + "description": "When set to \"true\", the \"nextTab\" and \"prevTab\" commands will use the tab switcher UI.", + "type": "boolean" } }, "required": [ diff --git a/src/cascadia/TerminalApp/CommandPalette.cpp b/src/cascadia/TerminalApp/CommandPalette.cpp index e2096079d8e..a8d0cb12d88 100644 --- a/src/cascadia/TerminalApp/CommandPalette.cpp +++ b/src/cascadia/TerminalApp/CommandPalette.cpp @@ -7,7 +7,6 @@ #include "ActionArgs.h" #include "Command.h" -#include #include #include "CommandPalette.g.cpp" diff --git a/src/cascadia/TerminalApp/Resources/en-US/Resources.resw b/src/cascadia/TerminalApp/Resources/en-US/Resources.resw index c66d5e4878f..8812604d0b0 100644 --- a/src/cascadia/TerminalApp/Resources/en-US/Resources.resw +++ b/src/cascadia/TerminalApp/Resources/en-US/Resources.resw @@ -577,7 +577,7 @@ Select color scheme... - Tab Search + Search for tab... Tab Switcher diff --git a/src/cascadia/TerminalApp/lib/pch.h b/src/cascadia/TerminalApp/lib/pch.h index dcac6c4e1ab..7962458b6ed 100644 --- a/src/cascadia/TerminalApp/lib/pch.h +++ b/src/cascadia/TerminalApp/lib/pch.h @@ -54,6 +54,8 @@ #include +#include + // Including TraceLogging essentials for the binary #include #include From 054219ab9f17640df8c813f36f2420631a2c998a Mon Sep 17 00:00:00 2001 From: Leon Liang Date: Thu, 20 Aug 2020 21:08:38 -0700 Subject: [PATCH 18/18] missed this one --- src/cascadia/TerminalApp/GlobalAppSettings.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cascadia/TerminalApp/GlobalAppSettings.h b/src/cascadia/TerminalApp/GlobalAppSettings.h index 1a6d41d3d7b..d78d15a8e34 100644 --- a/src/cascadia/TerminalApp/GlobalAppSettings.h +++ b/src/cascadia/TerminalApp/GlobalAppSettings.h @@ -82,7 +82,7 @@ class TerminalApp::GlobalAppSettings final GETSET_PROPERTY(bool, DebugFeaturesEnabled); // default value set in constructor GETSET_PROPERTY(bool, StartOnUserLogin, false); GETSET_PROPERTY(bool, AlwaysOnTop, false); - GETSET_PROPERTY(bool, UseTabSwitcher, false); + GETSET_PROPERTY(bool, UseTabSwitcher, true); private: std::optional _unparsedDefaultProfile;