From 1a1580a2547c84265bf42aba3f0b25c9ad397110 Mon Sep 17 00:00:00 2001 From: NRK Date: Mon, 16 Dec 2024 01:05:45 +0000 Subject: [PATCH] fix bug in Ctrl-W in xreadline implementation when there's multiple spaces, the previous logic didn't erase them, E.g: a word | < before a word | < after Ctrl-w this patch brings the behavior closer to readlines: a word | < before a | < after Ctrl-w this also slightly changes the behavior since '/' is no longer considered a boundary. --- src/nnn.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/nnn.c b/src/nnn.c index 2e43d4a07..d76bfd394 100644 --- a/src/nnn.c +++ b/src/nnn.c @@ -3718,13 +3718,13 @@ static char *xreadline(const char *prefill, const char *prompt) continue; case CONTROL('W'): printmsg(prompt); - do { - if (pos == 0) - break; - memmove(buf + pos - 1, buf + pos, - (len - pos) * WCHAR_T_WIDTH); - --pos, --len; - } while (buf[pos - 1] != ' ' && buf[pos - 1] != '/'); // NOLINT + lpos = pos; + while (pos > 0 && ISSPACE_(buf[pos - 1])) + --pos; + while (pos > 0 && !ISSPACE_(buf[pos - 1])) + --pos; + memmove(buf + pos, buf + lpos, (len - lpos) * WCHAR_T_WIDTH); + len -= lpos - pos; continue; case CONTROL('K'): printmsg(prompt);