diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2015-09-08 07:39:21 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2015-09-08 07:39:21 -0700 |
commit | 4ced8d1bf77a6d42d76843e345bef6d9f765d021 (patch) | |
tree | c54ecc31e0af375fa0670c95a3e24d82f951e5c5 /linenoise | |
parent | 9b2b5892cbcd6b78e3a96678581f0c8c24f7d6bb (diff) | |
download | txr-4ced8d1bf77a6d42d76843e345bef6d9f765d021.tar.gz txr-4ced8d1bf77a6d42d76843e345bef6d9f765d021.tar.bz2 txr-4ced8d1bf77a6d42d76843e345bef6d9f765d021.zip |
linenoise: Ctrl-U deletes only to the left.
Ctrl-U does not traditionally delete the entire line
in line editors or text editors. Rather, it is a
"super backspace" to the beginning of the line.
* linenoise/linenoise.c (edit_delete_prev_all): New
static function.
(edit): Replace CTRL_U action with call to
edit_delete_prev_all.
Diffstat (limited to 'linenoise')
-rw-r--r-- | linenoise/linenoise.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/linenoise/linenoise.c b/linenoise/linenoise.c index 0fcd89fb..273e7645 100644 --- a/linenoise/linenoise.c +++ b/linenoise/linenoise.c @@ -687,6 +687,15 @@ static void edit_backspace(lino_t *l) { } } +/* Delete all characters to left of cursor. */ +static void edit_delete_prev_all(lino_t *l) +{ + memmove(l->data, l->data + l->dpos, l->dlen - l->dpos + 1); + l->dlen -= l->dpos; + l->dpos = 0; + refresh_line(l); +} + /* Delete the previosu word, maintaining the cursor at the start of the * current word. */ static void edit_delete_prev_word(lino_t *l) { @@ -877,10 +886,8 @@ static int edit(lino_t *l, const char *prompt) return -1; } break; - case CTRL_U: /* delete the whole line. */ - l->data[0] = '\0'; - l->dpos = l->dlen = 0; - refresh_line(l); + case CTRL_U: + edit_delete_prev_all(l); break; case CTRL_V: /* insert next char verbatim */ verbatim = 1; |