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 18:31:12 +0000
commit5168aa72cd43f42572ea32358c115a38f52a6032 (patch)
tree3aa080539468e194c11ce402907fa46b2dc3432f
parentMerge branch 'ime-preedit-cursor-at-the-end-of-the-preedit-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 00292541..57553609 100644
--- a/selection.c
+++ b/selection.c
@@ -1608,12 +1608,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);
xassert(i + 1 <= left);