summaryrefslogtreecommitdiff
path: root/vis.c
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2014-09-27 21:46:52 +0200
committerMarc André Tanner <mat@brain-dump.org>2014-09-27 21:47:25 +0200
commitaec267c31c75c4c669dc85191ceae04ed507dc0d (patch)
treefdfbdfb7f0aa681fcc5877f31ef567b83b078d9b /vis.c
parent521263a2c67d2b5df507858dcd240a9e42790780 (diff)
Improve cursor placement after shifting
This is still not entirely correct if multiple lines are involved and the cursor is at the end of the selection.
Diffstat (limited to 'vis.c')
-rw-r--r--vis.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/vis.c b/vis.c
index 9127c9e..7d6d348 100644
--- a/vis.c
+++ b/vis.c
@@ -566,13 +566,14 @@ static void op_shift_right(OperatorContext *c) {
text_insert(txt, pos, tab, tablen);
pos = text_line_prev(txt, pos);
} while (pos >= c->range.start && pos != prev_pos);
+ window_cursor_to(vis->win->win, c->pos + tablen);
editor_draw(vis);
}
static void op_shift_left(OperatorContext *c) {
Text *txt = vis->win->text;
size_t pos = text_line_begin(txt, c->range.end), prev_pos;
- size_t tabwidth = editor_tabwidth_get(vis);
+ size_t tabwidth = editor_tabwidth_get(vis), tablen;
/* if range ends at the begin of a line, skip line break */
if (pos == c->range.end)
@@ -589,9 +590,11 @@ static void op_shift_left(OperatorContext *c) {
for (len = 0; text_iterator_byte_get(&it, &c) && c == ' '; len++)
text_iterator_byte_next(&it, NULL);
}
- text_delete(txt, pos, MIN(len, tabwidth));
+ tablen = MIN(len, tabwidth);
+ text_delete(txt, pos, tablen);
pos = text_line_prev(txt, pos);
} while (pos >= c->range.start && pos != prev_pos);
+ window_cursor_to(vis->win->win, c->pos - tablen);
editor_draw(vis);
}