From 4ced8d1bf77a6d42d76843e345bef6d9f765d021 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 8 Sep 2015 07:39:21 -0700 Subject: 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. --- linenoise/linenoise.c | 15 +++++++++++---- 1 file 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; -- cgit v1.2.3