summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2015-09-25 07:06:06 -0700
committerKaz Kylheku <kaz@kylheku.com>2015-09-25 07:06:06 -0700
commita4ed02eba4316be14384d2e696ae11f6078360c0 (patch)
treeda6e96510823be03c211f87bea442cede35b4383
parenta64e990aca730a0c941f7b51e3d170631ff03ed0 (diff)
downloadtxr-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.
-rw-r--r--linenoise/linenoise.c36
-rw-r--r--txr.14
2 files changed, 34 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;
+ }
}
}
diff --git a/txr.1 b/txr.1
index 8ed59dbf..6eb155c4 100644
--- a/txr.1
+++ b/txr.1
@@ -33600,6 +33600,10 @@ such that the last character of the line is to the left of the cursor
position. On terminals which have the Home and End keys, these may also
be used instead of Ctrl-A and Ctrl-E.
+In multi-line mode, these commands jump to the beginning or end of the
+current physical line. In line mode, they move to the beginning or end of the
+edit buffer.
+
.NP* Jump to Matching Parenthesis
If the cursor is on an opening or closing parenthesis, brace or bracket,