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

Code before:
        if (inputText.size() > 0)
        {
            if (inputText[0] == L'>')
            {
                newMode = CommandPaletteMode::ActionMode;
            }
        }

        if (newMode != _currentMode)
        {
            //_switchToMode will remove the '>' character from the input.
            _switchToMode(newMode);
        }
    }

    Collections::IObservableVector<winrt::TerminalApp::FilteredCommand> CommandPalette::FilteredActions()
    {
        return _filteredActions;
    }

    void CommandPalette::SetActionMap(const Microsoft::Terminal::Settings::Model::IActionMapView& actionMap)
    {
        _actionMap = actionMap;
        _setCommands();
    }

    void CommandPalette::_setCommands()
    {
        if (_actionMap)
        {
            _allCommands.Clear();
            const auto expandedCommands{ _actionMap.ExpandedCommands() };
            for (const auto& action : expandedCommands)
            {
                const auto keyChordText{ KeyChordSerialization::ToString(_actionMap.GetKeyBindingForAction(action.ID())) };
                auto actionPaletteItem{ winrt::make<winrt::TerminalApp::implementation::ActionPaletteItem>(action, keyChordText) };
                auto filteredCommand{ winrt::make<FilteredCommand>(actionPaletteItem) };
                _allCommands.Append(filteredCommand);
            }

            if (Visibility() == Visibility::Visible && _currentMode == CommandPaletteMode::ActionMode)
            {
                _updateFilteredActions();
            }
        }
    }

    // Method Description:
    // - Replaces a list of filtered commands in the target collection with new
    //   commands based on the tabs in the source collection.
    // Although the source observable we still don't register on it,

Review comment (refactor):
`SetCommands` was only ever being called in conjunction with `SetActionMap`, so I figured it'd make more sense for this to just be a private helper that `SetActionMap` calls

Code after:
        if (inputText.size() > 0)
        {
            if (inputText[0] == L'>')
            {
                newMode = CommandPaletteMode::ActionMode;
            }
        }

        if (newMode != _currentMode)
        {
            //_switchToMode will remove the '>' character from the input.
            _switchToMode(newMode);
        }
    }

    Collections::IObservableVector<winrt::TerminalApp::FilteredCommand> CommandPalette::FilteredActions()
    {
        return _filteredActions;
    }

    void CommandPalette::SetActionMap(const Microsoft::Terminal::Settings::Model::IActionMapView& actionMap)
    {
        _actionMap = actionMap;
        _populateCommands();
    }

    void CommandPalette::_populateCommands()
    {
        _allCommands.Clear();
        if (_actionMap)
        {
            const auto expandedCommands{ _actionMap.ExpandedCommands() };
            for (const auto& action : expandedCommands)
            {
                const auto keyChordText{ KeyChordSerialization::ToString(_actionMap.GetKeyBindingForAction(action.ID())) };
                auto actionPaletteItem{ winrt::make<winrt::TerminalApp::implementation::ActionPaletteItem>(action, keyChordText) };
                auto filteredCommand{ winrt::make<FilteredCommand>(actionPaletteItem) };
                _allCommands.Append(filteredCommand);
            }

            if (Visibility() == Visibility::Visible && _currentMode == CommandPaletteMode::ActionMode)
            {
                _updateFilteredActions();
            }
        }
    }

    // Method Description:
    // - Replaces a list of filtered commands in the target collection with new
    //   commands based on the tabs in the source collection.
    // Although the source observable we still don't register on it,