aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-01-20 18:20:03 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-01-26 19:47:14 +0000
commitf32b9242419edea9c6c4812ee17fbbe5a9514e1d (patch)
treeb9089f93e8e55a0461845240d727d3e46dfa5fd6
parentime: fix rendering of pre-edit cursor when positioned after the pre-edit string (diff)
selection: replace \r\n and \n with \r, and strip \e from pasted text
Closes #305 Closes #306
-rw-r--r--selection.c30
1 files changed, 27 insertions, 3 deletions
diff --git a/selection.c b/selection.c
index 7f94b0a7..4d6bddf4 100644
--- a/selection.c
+++ b/selection.c
@@ -1303,12 +1303,36 @@ fdm_receive(struct fdm *fdm, int fd, int events, void *data)
if (count == 0)
break;
- /* Call cb while at same time replacing \r\n with \n */
+ /*
+ * Call cb while at same time replace:
+ * - \r\n -> \r
+ * - \n -> \r
+ * - \e -> <nothing> (i.e. strip ESC)
+ */
char *p = text;
size_t left = count;
again:
- for (size_t i = 0; i < left - 1; i++) {
- if (p[i] == '\r' && p[i + 1] == '\n') {
+ for (size_t i = 0; i < left; i++) {
+ switch (p[i]) {
+ default:
+ break;
+
+ case '\n':
+ p[i] = '\r';
+ break;
+
+ case '\r':
+ if (i + 1 < left && p[i + 1] == '\n') {
+ ctx->decoder(ctx, p, i + 1);
+
+ xassert(i + 2 <= left);
+ p += i + 2;
+ left -= i + 2;
+ goto again;
+ }
+ break;
+
+ case '\x1b':
ctx->decoder(ctx, p, i);
assert(i + 1 <= left);