aboutsummaryrefslogtreecommitdiff
path: root/vis-operators.c
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2017-03-22 09:27:29 +0100
committerMarc André Tanner <mat@brain-dump.org>2017-03-22 09:27:29 +0100
commitad857484fe02d39d08b62c16c32ad2bb4aeba30d (patch)
treef11c3d15059c63e15250a881b2bee3dd14f0b286 /vis-operators.c
parent617f5e2050d317d69336dd87c44787509c5fb861 (diff)
downloadvis-ad857484fe02d39d08b62c16c32ad2bb4aeba30d.tar.gz
vis-ad857484fe02d39d08b62c16c32ad2bb4aeba30d.tar.xz
vis: do not indent empty lines when right shifting with `>`
The exception being when the range is a single line.
Diffstat (limited to 'vis-operators.c')
-rw-r--r--vis-operators.c7
1 files 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);