aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/normal.c12
-rw-r--r--test/old/testdir/test_put.vim28
2 files changed, 38 insertions, 2 deletions
diff --git a/src/nvim/normal.c b/src/nvim/normal.c
index d69e43e6b3..8ff47097fa 100644
--- a/src/nvim/normal.c
+++ b/src/nvim/normal.c
@@ -6446,6 +6446,7 @@ static void nv_put_opt(cmdarg_T *cap, bool fix_indent)
bool was_visual = false;
int dir;
int flags = 0;
+ const int save_fen = curwin->w_p_fen;
if (cap->oap->op_type != OP_NOP) {
// "dp" is ":diffput"
@@ -6496,6 +6497,10 @@ static void nv_put_opt(cmdarg_T *cap, bool fix_indent)
savereg = copy_register(regname);
}
+ // Temporarily disable folding, as deleting a fold marker may cause
+ // the cursor to be included in a fold.
+ curwin->w_p_fen = false;
+
// To place the cursor correctly after a blockwise put, and to leave the
// text in the correct position when putting over a selection with
// 'virtualedit' and past the end of the line, we use the 'c' operator in
@@ -6546,9 +6551,12 @@ static void nv_put_opt(cmdarg_T *cap, bool fix_indent)
xfree(savereg);
}
- // What to reselect with "gv"? Selecting the just put text seems to
- // be the most useful, since the original text was removed.
if (was_visual) {
+ if (save_fen) {
+ curwin->w_p_fen = true;
+ }
+ // What to reselect with "gv"? Selecting the just put text seems to
+ // be the most useful, since the original text was removed.
curbuf->b_visual.vi_start = curbuf->b_op_start;
curbuf->b_visual.vi_end = curbuf->b_op_end;
// need to adjust cursor position
diff --git a/test/old/testdir/test_put.vim b/test/old/testdir/test_put.vim
index 69fd4643c1..b1cf268a58 100644
--- a/test/old/testdir/test_put.vim
+++ b/test/old/testdir/test_put.vim
@@ -294,5 +294,33 @@ func Test_put_in_last_displayed_line()
call StopVimInTerminal(buf)
endfunc
+func Test_put_visual_replace_whole_fold()
+ new
+ let lines = repeat(['{{{1', 'foo', 'bar', ''], 2)
+ call setline(1, lines)
+ setlocal foldmethod=marker
+ call setreg('"', 'baz')
+ call setreg('1', '')
+ normal! Vp
+ call assert_equal("{{{1\nfoo\nbar\n\n", getreg('1'))
+ call assert_equal(['baz', '{{{1', 'foo', 'bar', ''], getline(1, '$'))
+
+ bwipe!
+endfunc
+
+func Test_put_visual_replace_fold_marker()
+ new
+ let lines = repeat(['{{{1', 'foo', 'bar', ''], 4)
+ call setline(1, lines)
+ setlocal foldmethod=marker
+ normal! Gkzo
+ call setreg('"', '{{{1')
+ call setreg('1', '')
+ normal! Vp
+ call assert_equal("{{{1\n", getreg('1'))
+ call assert_equal(lines, getline(1, '$'))
+
+ bwipe!
+endfunc
" vim: shiftwidth=2 sts=2 expandtab