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,