From c93d2b1a2d9332bd0c477997d108ba8e9e84ca9c Mon Sep 17 00:00:00 2001 From: Giorgio Gallo Date: Sun, 7 Jan 2018 18:38:16 +0100 Subject: [PATCH] Non-bracketed paste support for DOS CRLFs. When pasting in non-bracketed more, all line endings (including DOS-style CRLFs) get normalized to a single CR to simulate a keypress of the key. --- src/input.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/input.rs b/src/input.rs index ff9b7b03..ff1eb796 100644 --- a/src/input.rs +++ b/src/input.rs @@ -240,7 +240,13 @@ impl Action { ctx.write_to_pty(contents.into_bytes()); ctx.write_to_pty(&b"\x1b[201~"[..]); } else { - ctx.write_to_pty(contents.replace("\n","\r").into_bytes()); + // In non-bracketed (ie: normal) mode, terminal applications cannot distinguish + // pasted data from keystrokes. + // In theory, we should construct the keystrokes needed to produce the data we are + // pasting... since that's neither practical nor sensible (and probably an impossible + // task to solve in a general way), we'll just replace line breaks (windows and unix + // style) with a singe carriage return (\r, which is what the Enter key produces). + ctx.write_to_pty(contents.replace("\r\n","\r").replace("\n","\r").into_bytes()); } } }