aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2015-11-17 22:43:21 +0100
committerMarc André Tanner <mat@brain-dump.org>2015-11-17 22:43:21 +0100
commitd4246cb8a14c77926a864d6e896b1e46332a16a1 (patch)
treea6709d0c406ac96f500bbb3fc041864a54ad9098
parent91c043a5382e142d7ea69d47c29c74a2172e9f60 (diff)
downloadvis-d4246cb8a14c77926a864d6e896b1e46332a16a1.tar.gz
vis-d4246cb8a14c77926a864d6e896b1e46332a16a1.tar.xz
vis: put in visual mode should replace the current selection
There are some combinations (e.g. line wise selection / character wise register content) which should probably be improved further. Also since vis currently neither supports the numbered registers "0 - "9 nor the small delete register "- the deleted text is not stored in any register. Notice that we can't call op_delete in the implementation because it would overwrite the register content we want to paste. Closes #113
-rw-r--r--vis-operators.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/vis-operators.c b/vis-operators.c
index 0923ef6..981922b 100644
--- a/vis-operators.c
+++ b/vis-operators.c
@@ -30,12 +30,18 @@ static size_t op_yank(Vis *vis, Text *txt, OperatorContext *c) {
static size_t op_put(Vis *vis, Text *txt, OperatorContext *c) {
size_t pos = c->pos;
+ bool sel = text_range_size(&c->range) > 0;
+ bool sel_linewise = sel && text_range_is_linewise(txt, &c->range);
+ if (sel) {
+ text_delete_range(txt, &c->range);
+ pos = c->pos = c->range.start;
+ }
switch (c->arg->i) {
case VIS_OP_PUT_AFTER:
case VIS_OP_PUT_AFTER_END:
- if (c->reg->linewise)
+ if (c->reg->linewise && !sel_linewise)
pos = text_line_next(txt, pos);
- else
+ else if (!sel)
pos = text_char_next(txt, pos);
break;
case VIS_OP_PUT_BEFORE: