diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2015-09-25 07:06:06 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2015-09-25 07:06:06 -0700 |
commit | a4ed02eba4316be14384d2e696ae11f6078360c0 (patch) | |
tree | da6e96510823be03c211f87bea442cede35b4383 /linenoise | |
parent | a64e990aca730a0c941f7b51e3d170631ff03ed0 (diff) | |
download | txr-a4ed02eba4316be14384d2e696ae11f6078360c0.tar.gz txr-a4ed02eba4316be14384d2e696ae11f6078360c0.tar.bz2 txr-a4ed02eba4316be14384d2e696ae11f6078360c0.zip |
linemode: multi-line behavior for Ctrl-A/Ctrl-E.
* linemode/linemode.c (edit_move_home, edit_move_end):
Check for multi-line mode and implement movement
within the physical line.
* txr.1: Documented.
Diffstat (limited to 'linenoise')
-rw-r--r-- | linenoise/linenoise.c | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/linenoise/linenoise.c b/linenoise/linenoise.c index 9319d52c..552b9183 100644 --- a/linenoise/linenoise.c +++ b/linenoise/linenoise.c @@ -1267,17 +1267,41 @@ static void edit_move_right(lino_t *l) { /* Move cursor to the start of the line. */ static void edit_move_home(lino_t *l) { - if (l->dpos != 0) { - l->dpos = 0; - l->need_refresh = 1; + if (!l->mlmode) { + if (l->dpos != 0) { + l->dpos = 0; + l->need_refresh = 1; + } + } else { + size_t dpos = l->dpos; + + while (dpos > 0 && l->data[dpos-1] != '\r') + dpos--; + + if (l->dpos != dpos) { + l->dpos = dpos; + l->need_refresh = 1; + } } } /* Move cursor to the end of the line. */ static void edit_move_end(lino_t *l) { - if (l->dpos != l->dlen) { - l->dpos = l->dlen; - l->need_refresh = 1; + if (!l->mlmode) { + if (l->dpos != l->dlen) { + l->dpos = l->dlen; + l->need_refresh = 1; + } + } else { + size_t dpos = l->dpos; + + dpos += strspn(l->data + dpos, "\r"); + dpos += strcspn(l->data + dpos, "\r"); + + if (l->dpos != dpos) { + l->dpos = dpos; + l->need_refresh = 1; + } } } |