diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2015-09-25 22:53:18 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2015-09-25 22:53:18 -0700 |
commit | 58f014b1a71c0052668863af4ba84c92c4916b98 (patch) | |
tree | 12a075bc66f5f050b71f785fde79139dae04e63e /linenoise/linenoise.c | |
parent | ddebbad496cdd19c6249211c8f00861161496124 (diff) | |
download | txr-58f014b1a71c0052668863af4ba84c92c4916b98.tar.gz txr-58f014b1a71c0052668863af4ba84c92c4916b98.tar.bz2 txr-58f014b1a71c0052668863af4ba84c92c4916b98.zip |
linenoise: fix broken move-to-end on Enter.
The switch to Ctr-A/Ctrl-E within a logical line
breaks when the edit_move_end function is relied upon
to go to the end of the buffer.
* linenoise/linenoise.c (edit_move_home): Restored
to original behavior.
(edit_move_sol): New static function that hosts new
behavior of edit_move_home: calls edit_move_home in
single-line mode, or implements move within logical
line in multi-line mode.
(edit_move_end): Restored to original behavior.
(edit_move_eol): New static function that hosts new
behavior of edit_move_end: calls edit_move_end in
single-line mode, or implements move within logical
line in multi-line mode.
(edit): Call edit_move_sol instead of edit_move_home,
and in editing functions onyl, call edit_move_eol
instead of edit_move_end.
Diffstat (limited to 'linenoise/linenoise.c')
-rw-r--r-- | linenoise/linenoise.c | 44 |
1 files changed, 26 insertions, 18 deletions
diff --git a/linenoise/linenoise.c b/linenoise/linenoise.c index 552b9183..2ba472f5 100644 --- a/linenoise/linenoise.c +++ b/linenoise/linenoise.c @@ -1265,13 +1265,17 @@ static void edit_move_right(lino_t *l) { } } -/* Move cursor to the start of the line. */ -static void edit_move_home(lino_t *l) { +static void edit_move_home(lino_t *l) +{ + if (l->dpos != 0) { + l->dpos = 0; + l->need_refresh = 1; + } +} + +static void edit_move_sol(lino_t *l) { if (!l->mlmode) { - if (l->dpos != 0) { - l->dpos = 0; - l->need_refresh = 1; - } + edit_move_home(l); } else { size_t dpos = l->dpos; @@ -1285,13 +1289,17 @@ static void edit_move_home(lino_t *l) { } } -/* Move cursor to the end of the line. */ -static void edit_move_end(lino_t *l) { +static void edit_move_end(lino_t *l) +{ + if (l->dpos != l->dlen) { + l->dpos = l->dlen; + l->need_refresh = 1; + } +} + +static void edit_move_eol(lino_t *l) { if (!l->mlmode) { - if (l->dpos != l->dlen) { - l->dpos = l->dlen; - l->need_refresh = 1; - } + edit_move_end(l); } else { size_t dpos = l->dpos; @@ -1859,10 +1867,10 @@ static int edit(lino_t *l, const char *prompt) edit_move_left(l); break; case 'H': /* Home */ - edit_move_home(l); + edit_move_sol(l); break; case 'F': /* End*/ - edit_move_end(l); + edit_move_eol(l); break; } } @@ -1872,10 +1880,10 @@ static int edit(lino_t *l, const char *prompt) else if (seq[0] == 'O') { switch(seq[1]) { case 'H': /* Home */ - edit_move_home(l); + edit_move_sol(l); break; case 'F': /* End*/ - edit_move_end(l); + edit_move_eol(l); break; } } @@ -1933,10 +1941,10 @@ static int edit(lino_t *l, const char *prompt) edit_delete_to_eol(l); break; case CTL('A'): - edit_move_home(l); + edit_move_sol(l); break; case CTL('E'): - edit_move_end(l); + edit_move_eol(l); break; case CTL(']'): edit_move_matching_paren(l); |