mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-04 04:06:06 -05: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
74f92c3959
commit
5168aa72cd
1 changed files with 27 additions and 3 deletions
30
selection.c
30
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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue