From 485c473e76e7b90676a484d0f433d713f0c4c9ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Wed, 16 Mar 2022 20:17:02 +0100 Subject: [PATCH] =?UTF-8?q?selection:=20don=E2=80=99t=20translate=20\r=20t?= =?UTF-8?q?o=20\n=20when=20pasting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In non-bracketed paste mode, we translate \n to \r, and \r\n to \r. The latter matches XTerm, urxvt, alacritty and kitty. The former matches alacritty and kitty (xterm and urxvt just blindly replaces all \n occurrences with \r, meaning \r\n is translated to \r\r. For some reason, we then unconditionally translated all \r back to \n, regardless of whether bracketed paste was enabled or not. Unsure why/where this comes from, but it doesn't match any of the other terminal emulators I tested. One example where this caused issues is in older versions of nano (at least up to 2.9). Closes #980 --- CHANGELOG.md | 2 ++ selection.c | 9 ++------- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f3baa0ee..0fb7015b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -58,6 +58,8 @@ sequences (https://codeberg.org/dnkl/foot/issues/325). * OSC-4 and OSC-11 replies now uses four digits instead of 2 (https://codeberg.org/dnkl/foot/issues/971). +* `\r` is no longer translated to `\n` when pasting clipboard data + (https://codeberg.org/dnkl/foot/issues/980). ### Deprecated diff --git a/selection.c b/selection.c index e9a9f752..fbd0f484 100644 --- a/selection.c +++ b/selection.c @@ -1638,11 +1638,6 @@ fdm_receive_timeout(struct fdm *fdm, int fd, int events, void *data) static void fdm_receive_decoder_plain(struct clipboard_receive *ctx, char *data, size_t size) { - /* \r -> \n */ - for (size_t i = 0; i < size; i++) { - if (data[i] == '\r') - data[i] = '\n'; - } ctx->cb(data, size, ctx->user); } @@ -1760,8 +1755,8 @@ fdm_receive(struct fdm *fdm, int fd, int events, void *data) /* * Call cb while at same time replace: - * - \r\n -> \r - * - \n -> \r + * - \r\n -> \r (non-bracketed paste) + * - \n -> \r (non-bracketed paste) * - C0 -> (strip non-formatting C0 characters) * - \e -> (i.e. strip ESC) */