From 4c82a7c430c58aed7b31963f48e754ca87a4401e Mon Sep 17 00:00:00 2001 From: Kiminori Kaburagi Date: Tue, 15 Dec 2020 02:11:24 +0900 Subject: [PATCH] Enable shortcut while CommandPalette is open (#8044) ## Summary of the Pull Request It is maybe not the best way since I had to get all the cases for key handling so I just created for each of them. As a result the code get longer(not optimized). Most difficult thing was Next tab and Previous tab I just could not solve it. ### 9 commands that couldn't enabled > < 1. Increase font size -> could not find VirtualKey for "-" 2. Decrease font size -> could not find VirtualKey for "+" 3. Split pane, split:horizontal -> could not find VirtualKey for "-" 4. Split pane, split:vertical -> could not find VirtualKey for "+" 5. Open default settings -> could not find VirtualKey for "," 6. Open settings file -> could not find VirtualKey for "," 7. Open new tab dropdown -> could not resolve keybindings 8. Next tab -> could not resolve keybindings 9. Previous tab -> could not resolve keybindings ## References ## PR Checklist * [x] Closes #6679 * [x] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA * [ ] Tests added/passed * [ ] Documentation updated. If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/terminal) and link it here: #xxx * [ ] Schema updated. * [ ] I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: #xxx ## Detailed Description of the Pull Request / Additional comments ## Validation Steps Performed --- src/cascadia/TerminalApp/CommandPalette.cpp | 26 ++++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/cascadia/TerminalApp/CommandPalette.cpp b/src/cascadia/TerminalApp/CommandPalette.cpp index d1886a40a022..946c3a1998ea 100644 --- a/src/cascadia/TerminalApp/CommandPalette.cpp +++ b/src/cascadia/TerminalApp/CommandPalette.cpp @@ -6,6 +6,7 @@ #include "TabPaletteItem.h" #include "CommandLinePaletteItem.h" #include "CommandPalette.h" +#include "AppLogic.h" #include @@ -281,7 +282,8 @@ namespace winrt::TerminalApp::implementation // Method Description: // - Process keystrokes in the input box. This is used for moving focus up // and down the list of commands in Action mode, and for executing - // commands in both Action mode and Commandline mode. + // commands in both Action mode and Commandline mode. This would also + // enable users to perform action using shortcuts when command palette is open. // Arguments: // - e: the KeyRoutedEventArgs containing info about the keystroke. // Return Value: @@ -291,8 +293,24 @@ namespace winrt::TerminalApp::implementation { auto key = e.OriginalKey(); 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); + + winrt::Microsoft::Terminal::TerminalControl::KeyChord kc{ ctrlDown, altDown, shiftDown, static_cast(key) }; + auto setting = AppLogic::CurrentAppSettings(); + auto keymap = setting.GlobalSettings().KeyMap(); + const auto action = keymap.TryLookup(kc); - if (key == VirtualKey::Up) + if (action) + { + if (action.Action() != ShortcutAction::ToggleCommandPalette) + { + _close(); + } + _dispatch.DoAction(action); + e.Handled(true); + } + else if (key == VirtualKey::Up) { // Action Mode: Move focus to the next item in the list. SelectNextItem(false); @@ -357,10 +375,6 @@ namespace winrt::TerminalApp::implementation // 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,