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

Code before:
        if (const auto filteredCommand = selectedCommand.try_as<winrt::TerminalApp::FilteredCommand>())
        {
            _dispatchCommand(filteredCommand);
        }
    }

    // Method Description:
    // - 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:

Review comment (suggestion):
```suggestion
        const auto listViewItem = sender.try_as<winrt::Windows::UI::Xaml::Controls::ListViewItem>();
```

Code after:
        if (const auto filteredCommand = selectedCommand.try_as<winrt::TerminalApp::FilteredCommand>())
        {
            _dispatchCommand(filteredCommand);
        }
    }

    // Method Description:
    // - 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*/,