From: Olivier Matz Date: Sun, 13 Mar 2011 17:39:22 +0000 (+0100) Subject: rdline: fix buffer when user validates with the cursor at the middle X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=74e2889a2cee53b7b7ac15e9c6b319be4eeb4fc1;p=libcmdline.git rdline: fix buffer when user validates with the cursor at the middle Signed-off-by: Olivier Matz --- diff --git a/src/lib/cmdline_rdline.c b/src/lib/cmdline_rdline.c index ee78cb2..8d07b02 100644 --- a/src/lib/cmdline_rdline.c +++ b/src/lib/cmdline_rdline.c @@ -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: