Commit c1c5a026d03ce58e7eb51cb5778e4226635d186f

antirez 2014-09-03T11:49:43

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 @@ static int linenoiseEdit(int stdin_fd, int stdout_fd, char *buf, size_t buflen, 
         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 @@ static int linenoiseEdit(int stdin_fd, int stdout_fd, char *buf, size_t buflen, 
         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 {