diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2018-02-28 19:45:26 +0100 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2018-02-28 19:45:26 +0100 |
| commit | 113a6a6a84198432ed9258f4abd5ec490a64c518 (patch) | |
| tree | c1f11d636ca00fb5316308fda2bdcf6a0addd27b | |
| parent | 26455fe82eab962716123d65fac6ab776992c313 (diff) | |
| download | vis-113a6a6a84198432ed9258f4abd5ec490a64c518.tar.gz vis-113a6a6a84198432ed9258f4abd5ec490a64c518.tar.xz | |
vis: improve handling of linewise ranges in change operator
| -rw-r--r-- | text-objects.c | 2 | ||||
| -rw-r--r-- | vis-operators.c | 8 |
2 files changed, 7 insertions, 3 deletions
diff --git a/text-objects.c b/text-objects.c index 1f44222..fcd0158 100644 --- a/text-objects.c +++ b/text-objects.c @@ -375,7 +375,7 @@ Filerange text_range_linewise(Text *txt, Filerange *rin) { } bool text_range_is_linewise(Text *txt, Filerange *r) { - return text_range_valid(r) && + return text_range_size(r) > 0 && r->start == text_line_begin(txt, r->start) && r->end == text_line_begin(txt, r->end); } diff --git a/vis-operators.c b/vis-operators.c index 299bc56..0e8ff30 100644 --- a/vis-operators.c +++ b/vis-operators.c @@ -17,10 +17,14 @@ static size_t op_delete(Vis *vis, Text *txt, OperatorContext *c) { } static size_t op_change(Vis *vis, Text *txt, OperatorContext *c) { + bool linewise = c->linewise || text_range_is_linewise(txt, &c->range); op_delete(vis, txt, c); size_t pos = c->range.start; - if (c->linewise) - pos = vis_text_insert_nl(vis, txt, pos > 0 ? pos-1 : pos); + if (linewise) { + size_t newpos = vis_text_insert_nl(vis, txt, pos > 0 ? pos-1 : pos); + if (pos > 0) + pos = newpos; + } return pos; } |
