Repository: microsoft/terminal
File: src/cascadia/TerminalSettingsModel/ActionMap.cpp (C++)

Code before:
        for (auto nameAndCommand : commandsToExpand)
        {
            copyOfCommands.Insert(nameAndCommand.Key(), nameAndCommand.Value());
        }

        implementation::Command::ExpandCommands(copyOfCommands,
                                                profiles,
                                                winrt::param::vector_view<Model::ColorScheme>{ sortedSchemes });

        _ExpandedCommandsCache = winrt::single_threaded_vector<Model::Command>();
        for (const auto& [_, command] : copyOfCommands)
        {
            _ExpandedCommandsCache.Append(command);
        }
    }
    IVector<Model::Command> ActionMap::ExpandedCommands()
    {
        return _ExpandedCommandsCache;
    }

    IVector<Model::Command> _filterToSendInput(IMapView<hstring, Model::Command> nameMap,
                                               winrt::hstring currentCommandline)
    {
        auto results = winrt::single_threaded_vector<Model::Command>();

        auto backspaces = std::wstring(currentCommandline.size(), L'\x7f');

        // Helper to clone a sendInput command into a new Command, with the
        // input trimmed to account for the currentCommandline
        auto createInputAction = [&](const Model::Command& command) -> Model::Command {
            winrt::com_ptr<implementation::Command> cmdImpl;
            cmdImpl.copy_from(winrt::get_self<implementation::Command>(command));

            const auto inArgs{ command.ActionAndArgs().Args().try_as<Model::SendInputArgs>() };

            auto args = winrt::make_self<SendInputArgs>(
                winrt::hstring{ fmt::format(L"{}{}", backspaces, inArgs ? inArgs.Input() : L"") });
            Model::ActionAndArgs actionAndArgs{ ShortcutAction::SendInput, *args };

            auto copy = cmdImpl->Copy();
            copy->ActionAndArgs(actionAndArgs);

            return *copy;
        };

        // iterate over all the commands in all our actions...
        for (auto&& [name, command] : nameMap)
        {
            // If this is not a nested command, and it's a sendInput command...
            if (!command.HasNestedCommands() &&
                command.ActionAndArgs().Action() == ShortcutAction::SendInput)

Review comment (suggestion):
```suggestion
        const auto backspaces = std::wstring(currentCommandline.size(), L'\x7f');
```

Code after:
        for (auto nameAndCommand : commandsToExpand)
        {
            copyOfCommands.Insert(nameAndCommand.Key(), nameAndCommand.Value());
        }

        implementation::Command::ExpandCommands(copyOfCommands,
                                                profiles,
                                                winrt::param::vector_view<Model::ColorScheme>{ sortedSchemes });

        _ExpandedCommandsCache = winrt::single_threaded_vector<Model::Command>();
        for (const auto& [_, command] : copyOfCommands)
        {
            _ExpandedCommandsCache.Append(command);
        }
    }
    IVector<Model::Command> ActionMap::ExpandedCommands()
    {
        return _ExpandedCommandsCache;
    }

    IVector<Model::Command> _filterToSendInput(IMapView<hstring, Model::Command> nameMap,
                                               winrt::hstring currentCommandline)
    {
        auto results = winrt::single_threaded_vector<Model::Command>();

        const auto numBackspaces = currentCommandline.size();
        // Helper to clone a sendInput command into a new Command, with the
        // input trimmed to account for the currentCommandline
        auto createInputAction = [&](const Model::Command& command) -> Model::Command {
            winrt::com_ptr<implementation::Command> cmdImpl;
            cmdImpl.copy_from(winrt::get_self<implementation::Command>(command));

            const auto inArgs{ command.ActionAndArgs().Args().try_as<Model::SendInputArgs>() };

            auto args = winrt::make_self<SendInputArgs>(
                winrt::hstring{ fmt::format(FMT_COMPILE(L"{:\x7f^{}}{}"),
                                            L"",
                                            numBackspaces,
                                            (std::wstring_view)(inArgs ? inArgs.Input() : L"")) });
            Model::ActionAndArgs actionAndArgs{ ShortcutAction::SendInput, *args };

            auto copy = cmdImpl->Copy();
            copy->ActionAndArgs(actionAndArgs);

            return *copy;
        };

        // iterate over all the commands in all our actions...
        for (auto&& [name, command] : nameMap)
        {
            // If this is not a nested command, and it's a sendInput command...