From 3ca6f9fe0b61995d4b1b88b57c6306e9bb066980 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Wed, 16 Oct 2019 21:14:45 +0200 Subject: [PATCH] selection: replace \r\n with \n in pasted text --- selection.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/selection.c b/selection.c index 72e56ec0..d5b89dba 100644 --- a/selection.c +++ b/selection.c @@ -517,6 +517,14 @@ text_from_clipboard(struct terminal *term, uint32_t serial, } else if (amount == 0) break; + /* Replace \r\n with \n */ + for (size_t i = 0; i < amount - 1; i++) { + if (text[i] == '\r' && text[i + 1] == '\n') { + memmove(&text[i], &text[i + 1], amount - i - 1); + amount--; + } + } + cb(text, amount, user); } @@ -645,6 +653,14 @@ text_from_primary( } else if (amount == 0) break; + /* Replace \r\n with \n */ + for (size_t i = 0; i < amount - 1; i++) { + if (text[i] == '\r' && text[i + 1] == '\n') { + memmove(&text[i], &text[i + 1], amount - i - 1); + amount--; + } + } + cb(text, amount, user); }