Repository: microsoft/terminal
File: src/cascadia/TerminalApp/CommandPalette.cpp (C++)

Code before:
            // using as the action mode indicator. Switch into commandline mode.
            _switchToMode(CommandPaletteMode::CommandlineMode);
            e.Handled(true);
        }
        else if (key == VirtualKey::C && ctrlDown)
        {
            _searchBox().CopySelectionToClipboard();
            e.Handled(true);
        }
        else if (key == VirtualKey::V && ctrlDown)
        {
            _searchBox().PasteFromClipboard();
            e.Handled(true);
        }
        else if (key == VirtualKey::Right)
        {
            if (_currentMode == CommandPaletteMode::CommandlineMode)
            {
                if (const auto command{ _filteredActionsView().SelectedItem().try_as<winrt::TerminalApp::FilteredCommand>() })
                {
                    _searchBox().Text(command.Item().Name());
                    _searchBox().Select(_searchBox().Text().size(), 0);
                    _searchBox().Focus(FocusState::Programmatic);
                }
            }
            e.Handled(true);
        }
    }

    // Method Description:
    // - 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)
    {
        auto handled = false;
        if (_currentMode == CommandPaletteMode::TabSwitchMode)
        {
            if (vkey == VK_MENU && !down)
            {
                _anchorKeyUpHandler();
                handled = true;
            }
        }
        return handled;
    }

    void CommandPalette::_keyUpHandler(IInspectable const& /*sender*/,
                                       Windows::UI::Xaml::Input::KeyRoutedEventArgs const& e)
    {
        if (_currentMode == CommandPaletteMode::TabSwitchMode)

Review comment (refactor):
probably want to move this into the if block. Can you still move in the text box with left/right arrow keys after this change to edit what you're typing? 

Code after:
            // using as the action mode indicator. Switch into commandline mode.
            _switchToMode(CommandPaletteMode::CommandlineMode);
            e.Handled(true);
        }
        else if (key == VirtualKey::C && ctrlDown)
        {
            _searchBox().CopySelectionToClipboard();
            e.Handled(true);
        }
        else if (key == VirtualKey::V && ctrlDown)
        {
            _searchBox().PasteFromClipboard();
            e.Handled(true);
        }
        else if (key == VirtualKey::Right && _currentMode == CommandPaletteMode::CommandlineMode)
        {
            if (const auto command{ _filteredActionsView().SelectedItem().try_as<winrt::TerminalApp::FilteredCommand>() })
            {
                _searchBox().Text(command.Item().Name());
                _searchBox().Select(_searchBox().Text().size(), 0);
                _searchBox().Focus(FocusState::Programmatic);
                _filteredActionsView().SelectedIndex(-1);
                e.Handled(true);
            }
        }
    }

    // Method Description:
    // - 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)
    {
        auto handled = false;
        if (_currentMode == CommandPaletteMode::TabSwitchMode)
        {
            if (vkey == VK_MENU && !down)
            {
                _anchorKeyUpHandler();
                handled = true;
            }
        }
        return handled;
    }

    void CommandPalette::_keyUpHandler(IInspectable const& /*sender*/,
                                       Windows::UI::Xaml::Input::KeyRoutedEventArgs const& e)
    {
        if (_currentMode == CommandPaletteMode::TabSwitchMode)
        {
            _anchorKeyUpHandler();