Move to end before return when in multi-line mode. This makes sure that if we are editing in multi-line mode a line that actually spawns across multiple lines, the next output performed by the application using linenoise will not overwrite the edited line.
diff --git a/linenoise.c b/linenoise.c index 13f0865..36c0c5f 100644 --- a/linenoise.c +++ b/linenoise.c
@@ -771,6 +771,7 @@ case ENTER: /* enter */ history_len--; free(history[history_len]); + if (mlmode) linenoiseEditMoveEnd(&l); return (int)l.len; case CTRL_C: /* ctrl-c */ errno = EAGAIN; @@ -779,8 +780,8 @@ case 8: /* ctrl-h */ linenoiseEditBackspace(&l); break; - case CTRL_D: /* ctrl-d, remove char at right of cursor, or of the - line is empty, act as end-of-file. */ + case CTRL_D: /* ctrl-d, remove char at right of cursor, or if the + line is empty, act as end-of-file. */ if (l.len > 0) { linenoiseEditDelete(&l); } else {