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

Code before:
    // - This event is called when the user's mouse pointer enters an individual
    //   item from the list. We'll get the item that was hovered and "preview"
    //   the command that the user hovered. To do that, we'll dispatch the switch
    //   to tab command for this tab, but not dismiss the switcher.
    //
    // Arguments:
    // - sender: the UI element that raised the event.
    // Return Value:
    // - <none>
    void CommandPalette::_listItemPointerEntered(const winrt::Windows::Foundation::IInspectable& sender,
                                                 const winrt::Windows::UI::Xaml::Input::PointerRoutedEventArgs& /*args*/)
    {
        // cancel any pending exit timer to prevent an unwanted preview revert
        if (_pointerExitTimer)
        {
            _pointerExitTimer.Stop();
        }

        auto listViewItem = sender.try_as<winrt::Windows::UI::Xaml::Controls::ListViewItem>();
        if (_currentMode == CommandPaletteMode::ActionMode && listViewItem)
        {
            const auto enteredItem = listViewItem.Content();
            if (const auto filteredCommand{ enteredItem.try_as<winrt::TerminalApp::FilteredCommand>() })
            {
                // only preview submenu items (unsure about this as a requirement since for now we only preview color schemes)
                if (_nestedActionStack.Size() > 0)
                {
                    if (const auto actionPaletteItem{ filteredCommand.Item().try_as<winrt::TerminalApp::ActionPaletteItem>() })
                    {
                        // immediately preview the hovered scheme
                        PreviewAction.raise(*this, actionPaletteItem.Command());
                    }
                }
            }
        }
    }

    // Method Description:
    // - This event is called when the user's mouse pointer exits an individual
    //   item from the list. We then revert to previewing the selected item rather
    //   than the hovered one, using a short delay (via a DispatcherTimer) to smooth
    //   transitions when rapidly moving between items.
    //
    // Arguments:
    // - <none>
    // Return Value:
    // - <none>
    void CommandPalette::_listItemPointerExited(const winrt::Windows::Foundation::IInspectable& /*sender*/,
                                                const winrt::Windows::UI::Xaml::Input::PointerRoutedEventArgs& /*args*/)
    {
        // if there is no exit timer, create one

Review comment (suggestion):
Good callout! But nah, we can get rid of this if-statement.

The idea here really is to just allow actions to be previewable via the mouse, not just color schemes (and especially not just the ones that are nested).

Code after:
    // - This event is called when the user's mouse pointer enters an individual
    //   item from the list. We'll get the item that was hovered and "preview"
    //   the command that the user hovered. To do that, we'll dispatch the switch
    //   to tab command for this tab, but not dismiss the switcher.
    //
    // Arguments:
    // - sender: the UI element that raised the event.
    // Return Value:
    // - <none>
    void CommandPalette::_listItemPointerEntered(const winrt::Windows::Foundation::IInspectable& sender,
                                                 const winrt::Windows::UI::Xaml::Input::PointerRoutedEventArgs& /*args*/)
    {
        // cancel any pending exit timer to prevent an unwanted preview revert
        if (_pointerExitTimer)
        {
            _pointerExitTimer.Stop();
        }

        const auto listViewItem = sender.try_as<winrt::Windows::UI::Xaml::Controls::ListViewItem>();
        if (_currentMode == CommandPaletteMode::ActionMode && listViewItem)
        {
            const auto enteredItem = listViewItem.Content();
            if (const auto filteredCommand{ enteredItem.try_as<winrt::TerminalApp::FilteredCommand>() })
            {
                if (const auto actionPaletteItem{ filteredCommand.Item().try_as<winrt::TerminalApp::ActionPaletteItem>() })
                {
                    // immediately preview the hovered command
                    PreviewAction.raise(*this, actionPaletteItem.Command());
                }
            }
        }
    }

    // Method Description:
    // - This event is called when the user's mouse pointer exits an individual
    //   item from the list. We then revert to previewing the selected item rather
    //   than the hovered one, using a short delay (via a DispatcherTimer) to smooth
    //   transitions when rapidly moving between items.
    //
    // Arguments:
    // - <none>
    // Return Value:
    // - <none>
    void CommandPalette::_listItemPointerExited(const winrt::Windows::Foundation::IInspectable& /*sender*/,
                                                const winrt::Windows::UI::Xaml::Input::PointerRoutedEventArgs& /*args*/)
    {
        // if there is no exit timer, create one
        if (!_pointerExitTimer)
        {
            _pointerExitTimer = winrt::Windows::UI::Xaml::DispatcherTimer();
            _pointerExitTimer.Interval(std::chrono::milliseconds(10));