mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-24 09:05:48 -04:00
selection: replace \r\n and \n with \r, and strip \e from pasted text
Closes #305 Closes #306
This commit is contained in:
parent
adbf036053
commit
f32b924241
1 changed files with 27 additions and 3 deletions
30
selection.c
30
selection.c
|
|
@ -1303,12 +1303,36 @@ fdm_receive(struct fdm *fdm, int fd, int events, void *data)
|
||||||
if (count == 0)
|
if (count == 0)
|
||||||
break;
|
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;
|
char *p = text;
|
||||||
size_t left = count;
|
size_t left = count;
|
||||||
again:
|
again:
|
||||||
for (size_t i = 0; i < left - 1; i++) {
|
for (size_t i = 0; i < left; i++) {
|
||||||
if (p[i] == '\r' && p[i + 1] == '\n') {
|
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);
|
ctx->decoder(ctx, p, i);
|
||||||
|
|
||||||
assert(i + 1 <= left);
|
assert(i + 1 <= left);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue