From ad857484fe02d39d08b62c16c32ad2bb4aeba30d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Wed, 22 Mar 2017 09:27:29 +0100 Subject: vis: do not indent empty lines when right shifting with `>` The exception being when the range is a single line. --- vis-operators.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/vis-operators.c b/vis-operators.c index 494774c..446260d 100644 --- a/vis-operators.c +++ b/vis-operators.c @@ -107,10 +107,13 @@ static size_t op_shift_right(Vis *vis, Text *txt, OperatorContext *c) { /* if range ends at the begin of a line, skip line break */ if (pos == c->range.end) pos = text_line_prev(txt, pos); + bool multiple_lines = text_line_prev(txt, pos) >= c->range.start; do { - prev_pos = pos = text_line_begin(txt, pos); - if (text_insert(txt, pos, tab, tablen) && pos <= c->pos) + size_t end = text_line_end(txt, pos); + prev_pos = pos = text_line_begin(txt, end); + if ((!multiple_lines || pos != end) && + text_insert(txt, pos, tab, tablen) && pos <= c->pos) newpos += tablen; pos = text_line_prev(txt, pos); } while (pos >= c->range.start && pos != prev_pos); -- cgit v1.2.3