diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2010-05-17 12:30:44 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-05-17 12:30:44 +0200 |
commit | 1118d9b213e4cad56e6f79c1753e0a52defadaa5 (patch) | |
tree | 65c77fa078816d1100900998433440e365b1bd5f /libbb | |
parent | 786cce1871ade4240c629187d6609de155fe3536 (diff) | |
download | busybox-1118d9b213e4cad56e6f79c1753e0a52defadaa5.tar.gz |
lineedit: fix insertion deep inside line (*several lines* before end)
function old new delta
input_backward 212 229 +17
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/lineedit.c | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/libbb/lineedit.c b/libbb/lineedit.c index 36d057bbb..f7d3ffed8 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c @@ -486,15 +486,22 @@ static void input_backward(unsigned num) while (cursor < sv_cursor) put_cur_glyph_and_inc_cursor(); } else { - int count_y; - unsigned w; + int lines_up; + unsigned width; + /* num = chars to go back from the beginning of current line: */ num -= cmdedit_x; - w = cmdedit_termw; /* read volatile var once */ - count_y = 1 + (num / w); - cmdedit_y -= count_y; - cmdedit_x = w * count_y - num; - /* go to 1st column; go up; go to correct column */ - printf("\r" "\033[%uA" "\033[%uC", count_y, cmdedit_x); + width = cmdedit_termw; /* read volatile var once */ + /* num=1...w: one line up, w+1...2w: two, etc: */ + lines_up = 1 + (num - 1) / width; + cmdedit_x = (width * cmdedit_y - num) % width; + cmdedit_y -= lines_up; + /* go to 1st column; go up */ + printf("\r" "\033[%uA", lines_up); + /* go to correct column. + * xtarm, konsole, Linux VT interpret 0 as 1 below! wow. + * Need to *make sure* we skip it if cmdedit_x == 0 */ + if (cmdedit_x) + printf("\033[%uC", cmdedit_x); } } |