From 0b0cfc846c30bb56d0f46949ecd1223028f65bb1 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 21 Sep 2015 06:45:20 -0700 Subject: linenoise: do not undo to empty line * linenoise/linenoise.c (restore_undo): If an undo item wants to produce a completely blank line, then discard and skip it. --- linenoise/linenoise.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'linenoise/linenoise.c') diff --git a/linenoise/linenoise.c b/linenoise/linenoise.c index d0e3db1d..9dd43306 100644 --- a/linenoise/linenoise.c +++ b/linenoise/linenoise.c @@ -366,18 +366,23 @@ static void restore_undo(lino_t *l) int hidx = top->hist_index; if (hidx == INT_MAX || hidx == l->history_index) { - strcpy(l->data, top->data); - l->dlen = strlen(top->data); - l->dpos = top->dpos; - l->need_refresh = 1; + size_t dlen = strlen(top->data); + + if (dlen) { + strcpy(l->data, top->data); + l->dlen = dlen; + l->dpos = top->dpos; + l->need_refresh = 1; - if (hidx == l->history_index) { - int history_pos = l->history_len - 1 - l->history_index; - free(l->history[history_pos]); - l->history[history_pos] = chk_strdup_utf8(l->data); + if (hidx == l->history_index) { + int history_pos = l->history_len - 1 - l->history_index; + free(l->history[history_pos]); + l->history[history_pos] = chk_strdup_utf8(l->data); + } + delete_undo(ptop); + break; } delete_undo(ptop); - break; } else if (hidx >= l->history_len - 1) { delete_undo(ptop); } else { -- cgit v1.2.3