rdline: fix buffer when user validates with the cursor at the middle
authorOlivier Matz <zer0@droids-corp.org>
Sun, 13 Mar 2011 17:39:22 +0000 (18:39 +0100)
committerOlivier Matz <zer0@droids-corp.org>
Sun, 13 Mar 2011 17:39:22 +0000 (18:39 +0100)
Signed-off-by: Olivier Matz <zer0@droids-corp.org>
src/lib/cmdline_rdline.c

index ee78cb2..8d07b02 100644 (file)
@@ -462,7 +462,13 @@ rdline_parse_char(struct rdline *rdl, char c)
                }
 
                case CMDLINE_KEY_RETURN:
-               case CMDLINE_KEY_RETURN2:
+               case CMDLINE_KEY_RETURN2: {
+                       char tmp;
+                       while (!CIRBUF_IS_EMPTY(&rdl->right) &&
+                              (tmp = cirbuf_get_head(&rdl->right))) {
+                               cirbuf_del_head(&rdl->right);
+                               cirbuf_add_tail(&rdl->left, tmp);
+                       }
                        cirbuf_align_left(&rdl->left);
                        rdl->left_buf[CIRBUF_GET_LEN(&rdl->left)] = '\n';
                        rdl->left_buf[CIRBUF_GET_LEN(&rdl->left) + 1] = '\0';
@@ -491,7 +497,7 @@ rdline_parse_char(struct rdline *rdl, char c)
                                return RDLINE_RES_EXITED;
 #endif
                        return RDLINE_RES_VALIDATED;
-
+               }
 #ifndef NO_RDLINE_HISTORY
                case CMDLINE_KEY_UP_ARR:
                case CMDLINE_KEY_CTRL_P: