Skip to content

Commit

Permalink
ConPTY: when pasting, replace "\r\n" with "\n"
Browse files Browse the repository at this point in the history
On Windows, most copying-and-pasting will use CRLF vs. LF -- this means
that pasting from Windows *into* Alacritty will likely end-up with
duplicated newlines, as Alacritty will send *both* '\r' and '\n'.

This change replaces "\r\n" with "\n" when pasting, such that these
duplicated newlines do not appear.

See: alacritty#2324 (comment)
  • Loading branch information
aytey committed Apr 21, 2021
1 parent 28abb1f commit 8d2d1eb
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion alacritty/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ impl<'a, N: Notify + 'a, T: EventListener> input::ActionContext<T> for ActionCon
}
} else if self.terminal().mode().contains(TermMode::BRACKETED_PASTE) {
self.write_to_pty(&b"\x1b[200~"[..]);
self.write_to_pty(text.replace("\x1b", "").into_bytes());
self.write_to_pty(text.replace("\x1b", "").replace("\r\n", "\n").into_bytes());
self.write_to_pty(&b"\x1b[201~"[..]);
} else {
// In non-bracketed (ie: normal) mode, terminal applications cannot distinguish
Expand Down

5 comments on commit 8d2d1eb

@homedirectory
Copy link

@homedirectory homedirectory commented on 8d2d1eb Sep 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this issue is present not only on Windows, but on macOS too.
rebuilding alacritty with this one line modification completely solved the problem for me, it's strange that they haven't pulled this yet

@aytey
Copy link
Owner Author

@aytey aytey commented on 8d2d1eb Sep 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@homedirectory it appearing on macOS is super suspicious (to the extent that I can't believe it is true). Are you SSHing to a Windows machine from macOS?

@homedirectory
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andrewvaughanj no, i am not sshing to a windows machine

@aytey
Copy link
Owner Author

@aytey aytey commented on 8d2d1eb Sep 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you trying to copy a file with Windows line endings?

@homedirectory
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, i was testing it by copying text from different places (HTTP requests from BurpSuite, text from Wikipedia, etc.) and it always behaved the same

Please sign in to comment.