diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2015-09-21 06:45:20 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2015-09-21 06:45:20 -0700 |
commit | 0b0cfc846c30bb56d0f46949ecd1223028f65bb1 (patch) | |
tree | 27baba3bf201d9bae73e7fab2c02851a181026a1 /linenoise | |
parent | 1de86c685ff9a4a36014188c8ef24601d704157c (diff) | |
download | txr-0b0cfc846c30bb56d0f46949ecd1223028f65bb1.tar.gz txr-0b0cfc846c30bb56d0f46949ecd1223028f65bb1.tar.bz2 txr-0b0cfc846c30bb56d0f46949ecd1223028f65bb1.zip |
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.
Diffstat (limited to 'linenoise')
-rw-r--r-- | linenoise/linenoise.c | 23 |
1 files changed, 14 insertions, 9 deletions
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 { |