mirror of
https://github.com/microsoft/terminal.git
synced 2026-09-25 08:24:54 +00:00
Replacing \r\n line endings with \r line endings (#3449)
<!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? --> ## Summary of the Pull Request <!-- Other than the issue solved, is this relevant to any other issues/existing PRs? --> ## References #1091 #1094 #2390 #3314 <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist * [x] Closes #1091 * [x] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA * [ ] Tests added/passed * [ ] Requires documentation to be updated * [x] I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: #xxx <!-- Provide a more detailed description of the PR, other things fixed or any additional comments/features here --> ## Detailed Description of the Pull Request / Additional comments Combination of the PRs #1094, #2390, and #3314, especially as discussed in #3314. In short, this changes line endings from Windows-space \r\n to the more universal \r. <!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well --> ## Validation Steps Performed Copied and pasted text into the terminal without the patch, line endings were doubled. With the patch, line endings weren't doubled. -------------------- * Replacing \r\n line endings with \r line endings * Fixing Formatting
This commit is contained in:
@@ -1205,6 +1205,35 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
|
||||
_connection.WriteInput(wstr);
|
||||
}
|
||||
|
||||
// Method Description:
|
||||
// - Pre-process text pasted (presumably from the clipboard)
|
||||
// before sending it over the terminal's connection, converting
|
||||
// Windows-space \r\n line-endings to \r line-endings
|
||||
void TermControl::_SendPastedTextToConnection(const std::wstring& wstr)
|
||||
{
|
||||
// Some notes on this implementation:
|
||||
//
|
||||
// - std::regex can do this in a single line, but is somewhat
|
||||
// overkill for a simple search/replace operation (and its
|
||||
// performance guarantees aren't exactly stellar)
|
||||
// - The STL doesn't have a simple string search/replace method.
|
||||
// This fact is lamentable.
|
||||
// - This line-ending converstion is intentionally fairly
|
||||
// conservative, to avoid stripping out lone \n characters
|
||||
// where they could conceivably be intentional.
|
||||
|
||||
std::wstring stripped{ wstr };
|
||||
|
||||
std::wstring::size_type pos = 0;
|
||||
|
||||
while ((pos = stripped.find(L"\r\n", pos)) != std::wstring::npos)
|
||||
{
|
||||
stripped.replace(pos, 2, L"\r");
|
||||
}
|
||||
|
||||
_connection.WriteInput(stripped);
|
||||
}
|
||||
|
||||
// Method Description:
|
||||
// - Update the font with the renderer. This will be called either when the
|
||||
// font changes or the DPI changes, as DPI changes will necessitate a
|
||||
@@ -1456,7 +1485,7 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
|
||||
{
|
||||
// attach TermControl::_SendInputToConnection() as the clipboardDataHandler.
|
||||
// This is called when the clipboard data is loaded.
|
||||
auto clipboardDataHandler = std::bind(&TermControl::_SendInputToConnection, this, std::placeholders::_1);
|
||||
auto clipboardDataHandler = std::bind(&TermControl::_SendPastedTextToConnection, this, std::placeholders::_1);
|
||||
auto pasteArgs = winrt::make_self<PasteFromClipboardEventArgs>(clipboardDataHandler);
|
||||
|
||||
// send paste event up to TermApp
|
||||
|
||||
@@ -165,6 +165,7 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
|
||||
void _BlinkCursor(Windows::Foundation::IInspectable const& sender, Windows::Foundation::IInspectable const& e);
|
||||
void _SetEndSelectionPointAtCursor(Windows::Foundation::Point const& cursorPosition);
|
||||
void _SendInputToConnection(const std::wstring& wstr);
|
||||
void _SendPastedTextToConnection(const std::wstring& wstr);
|
||||
void _SwapChainSizeChanged(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::SizeChangedEventArgs const& e);
|
||||
void _SwapChainScaleChanged(Windows::UI::Xaml::Controls::SwapChainPanel const& sender, Windows::Foundation::IInspectable const& args);
|
||||
void _DoResize(const double newWidth, const double newHeight);
|
||||
|
||||
Reference in New Issue
Block a user