aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2016-04-29 16:19:34 +0200
committerMarc André Tanner <mat@brain-dump.org>2016-04-29 16:19:34 +0200
commit78ea0cd428d2349f11d3f1f4abd00218a4b0f152 (patch)
treeaf07339f9b8e9f2a96326e83b01f923e0567d566
parent9c573eaf13f882bfb3deb44268bd5bd8947b0260 (diff)
downloadvis-78ea0cd428d2349f11d3f1f4abd00218a4b0f152.tar.gz
vis-78ea0cd428d2349f11d3f1f4abd00218a4b0f152.tar.xz
vis: improve cursor placement after join operator
Close #299
-rw-r--r--vis-operators.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/vis-operators.c b/vis-operators.c
index b2f3fc7..efc0dff 100644
--- a/vis-operators.c
+++ b/vis-operators.c
@@ -184,6 +184,7 @@ static size_t op_cursor(Vis *vis, Text *txt, OperatorContext *c) {
static size_t op_join(Vis *vis, Text *txt, OperatorContext *c) {
size_t pos = text_line_begin(txt, c->range.end), prev_pos;
+ Mark mark = NULL;
/* if operator and range are both linewise, skip last line break */
if (c->linewise && text_range_is_linewise(txt, &c->range)) {
@@ -200,12 +201,15 @@ static size_t op_join(Vis *vis, Text *txt, OperatorContext *c) {
if (pos >= c->range.start && end > pos) {
text_delete(txt, pos, end - pos);
text_insert(txt, pos, " ", 1);
+ if (!mark)
+ mark = text_mark_set(txt, pos);
} else {
break;
}
} while (pos != prev_pos);
- return c->range.start;
+ size_t newpos = text_mark_get(txt, mark);
+ return newpos != EPOS ? newpos : c->range.start;
}
static size_t op_insert(Vis *vis, Text *txt, OperatorContext *c) {