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

Code before:
            for (const auto& action : commandsToFilter)
            {
                // Update filter for all commands
                // This will modify the highlighting but will also lead to re-computation of weight (and consequently sorting).
                // Pay attention that it already updates the highlighting in the UI
                action.UpdateFilter(searchText);

                // if there is active search we skip commands with 0 weight
                if (searchText.empty() || action.Weight() > 0)
                {
                    actions.push_back(action);
                }
            }
        }

        // TODO (for discussion):
        //
        // Do we want sorting in the palette? I have it disabled, so results are
        // filtered, but still in the original order. This seems more correct,
        // but I could be convinced otherwise. It could maybe be a setting.

        // if (_mode == SuggestionsMode::Palette)
        // {
        //     // We want to present the commands sorted
        //     std::sort(actions.begin(), actions.end(), FilteredCommand::Compare);
        // }

        // Adjust the order of the results depending on if we're top-down or
        // bottom up. This way, the "first" / "best" match is always closest to
        // the cursor.
        if (_direction == TerminalApp::SuggestionsDirection::BottomUp)
        {
            // Reverse the list
            std::reverse(std::begin(actions), std::end(actions));
        }

        return actions;
    }

    // Method Description:
    // - Update our list of filtered actions to reflect the current contents of
    //   the input box.
    // Arguments:
    // - <none>
    // Return Value:
    // - <none>
    void SuggestionsControl::_updateFilteredActions()
    {
        auto actions = _collectFilteredActions();

        // Make _filteredActions look identical to actions, using only Insert and Remove.

Review comment (bug):
BARE TODO

I vote keep original order and we see how this feels in a bug bash or after some initial feedback.

Code after:
            for (const auto& action : commandsToFilter)
            {
                // Update filter for all commands
                // This will modify the highlighting but will also lead to re-computation of weight (and consequently sorting).
                // Pay attention that it already updates the highlighting in the UI
                action.UpdateFilter(searchText);

                // if there is active search we skip commands with 0 weight
                if (searchText.empty() || action.Weight() > 0)
                {
                    actions.push_back(action);
                }
            }
        }

        // No sorting in palette mode, so results are still filtered, but in the
        // original order. This feels more right for something like
        // recentCommands.
        //
        // This is in contrast to the Command Palette, which always sorts its
        // actions.

        // Adjust the order of the results depending on if we're top-down or
        // bottom up. This way, the "first" / "best" match is always closest to
        // the cursor.
        if (_direction == TerminalApp::SuggestionsDirection::BottomUp)
        {
            // Reverse the list
            std::reverse(std::begin(actions), std::end(actions));
        }

        return actions;
    }

    // Method Description:
    // - Update our list of filtered actions to reflect the current contents of
    //   the input box.
    // Arguments:
    // - <none>
    // Return Value:
    // - <none>
    void SuggestionsControl::_updateFilteredActions()
    {
        auto actions = _collectFilteredActions();

        // Make _filteredActions look identical to actions, using only Insert and Remove.
        // This allows WinUI to nicely animate the ListView as it changes.
        for (uint32_t i = 0; i < _filteredActions.Size() && i < actions.size(); i++)
        {
            for (auto j = i; j < _filteredActions.Size(); j++)
            {