Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial support for bracketed paste mode #8909

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/cascadia/TerminalControl/TermControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2056,6 +2056,17 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
std::wstring::size_type pos = 0;
std::wstring::size_type begin = 0;

auto bracket = [](const std::wstring& origin, const bool enabled) {
std::wstring bracketed{ origin };
if (enabled)
{
bracketed.insert(0, L"\x1b[200~");
bracketed.append(L"\x1b[201~");
}

return bracketed;
};

while ((pos = wstr.find(L"\n", pos)) != std::wstring::npos)
{
// copy up to but not including the \n
Expand All @@ -2071,13 +2082,15 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
begin = pos;
}

const bool enableBracket = _terminal->IsXtermBracketedPasteModeEnabled();

// If we entered the while loop even once, begin would be non-zero
// (because we set begin = pos right after incrementing pos)
// So, if begin is still zero at this point it means we never found a newline
// and we can just write the original string
if (begin == 0)
{
_connection.WriteInput(wstr);
_connection.WriteInput(bracket(wstr, enableBracket));
}
else
{
Expand All @@ -2087,7 +2100,7 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
// we may have removed some characters, so we may not need as much space
// as we reserved earlier
stripped.shrink_to_fit();
_connection.WriteInput(stripped);
_connection.WriteInput(bracket(stripped, enableBracket));
}

_terminal->ClearSelection();
Expand Down