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.
This commit is contained in:
NRK 2024-12-16 14:45:37 +00:00
parent d6b1b80e40
commit 942afdf445

View file

@ -180,6 +180,7 @@
#define MAX(x, y) ((x) > (y) ? (x) : (y)) #define MAX(x, y) ((x) > (y) ? (x) : (y))
#define ISODD(x) ((x) & 1) #define ISODD(x) ((x) & 1)
#define ISBLANK(x) ((x) == ' ' || (x) == '\t') #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 TOUPPER(ch) (((ch) >= 'a' && (ch) <= 'z') ? ((ch) - 'a' + 'A') : (ch))
#define TOLOWER(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') #define ISUPPER_(ch) ((ch) >= 'A' && (ch) <= 'Z')
@ -3717,13 +3718,13 @@ static char *xreadline(const char *prefill, const char *prompt)
continue; continue;
case CONTROL('W'): case CONTROL('W'):
printmsg(prompt); printmsg(prompt);
do { lpos = pos;
if (pos == 0) while (pos > 0 && ISSPACE(buf[pos-1]))
break; --pos;
memmove(buf + pos - 1, buf + pos, while (pos > 0 && !ISSPACE(buf[pos-1]))
(len - pos) * WCHAR_T_WIDTH); --pos;
--pos, --len; memmove(buf + pos, buf + lpos, (len - lpos) * WCHAR_T_WIDTH);
} while (buf[pos - 1] != ' ' && buf[pos - 1] != '/'); // NOLINT len -= lpos - pos;
continue; continue;
case CONTROL('K'): case CONTROL('K'):
printmsg(prompt); printmsg(prompt);