Replace \n with \r when pasting (Fixes #678)

Termux will now properly send \r to the terminal instead of \n when pasting
multiline strings.

This fixes cat not repeating back lines and nano accidentally justifying
text (because \n maps to ^J), as well as other potential issues.

This matches the behavior of other terminals, such as iTerm2 which explicitly
does it here:
https://github.com/gnachman/iTerm2/blob/f8a5930/sources/iTermPasteHelper.m#L113

Signed-off-by: easyaspi314 (Devin) <easyaspi314@users.noreply.github.com>
This commit is contained in:
easyaspi314 (Devin)
2018-06-10 22:48:35 -04:00
committed by Fredrik Fornwall
parent 80c81b274d
commit be6a73d862

View File

@@ -2338,6 +2338,9 @@ public final class TerminalEmulator {
public void paste(String text) {
// First: Always remove escape key and C1 control characters [0x80,0x9F]:
text = text.replaceAll("(\u001B|[\u0080-\u009F])", "");
// Second: Replace all newlines (\n) with carriage returns (\r).
text = text.replace('\n', '\r');
// Then: Implement bracketed paste mode if enabled:
boolean bracketed = isDecsetInternalBitSet(DECSET_BIT_BRACKETED_PASTE_MODE);
if (bracketed) mSession.write("\033[200~");