From 942afdf4454743be6065e022fc31271c75c0f01c Mon Sep 17 00:00:00 2001 From: NRK Date: Mon, 16 Dec 2024 14:45:37 +0000 Subject: [PATCH] make Ctrl+w in xreadline similar to readline's 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 readline's: a word | < before a | < after Ctrl-w this also slightly changes the behavior since '/' is no longer considered a boundary. --- src/nnn.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/nnn.c b/src/nnn.c index c2b7e08e..b0f2e0b2 100644 --- a/src/nnn.c +++ b/src/nnn.c @@ -180,6 +180,7 @@ #define MAX(x, y) ((x) > (y) ? (x) : (y)) #define ISODD(x) ((x) & 1) #define ISBLANK(x) ((x) == ' ' || (x) == '\t') +#define ISSPACE(x) (ISBLANK(x) || (x) == '\n' || (x) == '\r' || (x) == '\f' || (x) == '\v') #define TOUPPER(ch) (((ch) >= 'a' && (ch) <= 'z') ? ((ch) - 'a' + 'A') : (ch)) #define TOLOWER(ch) (((ch) >= 'A' && (ch) <= 'Z') ? ((ch) - 'A' + 'a') : (ch)) #define ISUPPER_(ch) ((ch) >= 'A' && (ch) <= 'Z') @@ -3717,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);