diff options
-rw-r--r-- | runtime/doc/builtin.txt | 2 | ||||
-rw-r--r-- | runtime/lua/vim/_meta/vimfn.lua | 2 | ||||
-rw-r--r-- | src/nvim/eval.lua | 2 | ||||
-rw-r--r-- | src/nvim/eval/funcs.c | 4 | ||||
-rw-r--r-- | test/old/testdir/test_visual.vim | 11 |
5 files changed, 18 insertions, 3 deletions
diff --git a/runtime/doc/builtin.txt b/runtime/doc/builtin.txt index 9c1855806e..d6a14d9227 100644 --- a/runtime/doc/builtin.txt +++ b/runtime/doc/builtin.txt @@ -2947,6 +2947,8 @@ getregion({pos1}, {pos2}, {type}) *getregion()* |visual-mode|, an empty list is returned. - If {pos1}, {pos2} or {type} is an invalid string, an empty list is returned. + - If {pos1} or {pos2} is a mark in different buffer, an empty + list is returned. Examples: > :xnoremap <CR> diff --git a/runtime/lua/vim/_meta/vimfn.lua b/runtime/lua/vim/_meta/vimfn.lua index 527113c016..623ce2bc0f 100644 --- a/runtime/lua/vim/_meta/vimfn.lua +++ b/runtime/lua/vim/_meta/vimfn.lua @@ -3553,6 +3553,8 @@ function vim.fn.getreginfo(regname) end --- |visual-mode|, an empty list is returned. --- - If {pos1}, {pos2} or {type} is an invalid string, an empty --- list is returned. +--- - If {pos1} or {pos2} is a mark in different buffer, an empty +--- list is returned. --- --- Examples: > --- :xnoremap <CR> diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua index 231dd1f9bf..9cca9c588a 100644 --- a/src/nvim/eval.lua +++ b/src/nvim/eval.lua @@ -4387,6 +4387,8 @@ M.funcs = { |visual-mode|, an empty list is returned. - If {pos1}, {pos2} or {type} is an invalid string, an empty list is returned. + - If {pos1} or {pos2} is a mark in different buffer, an empty + list is returned. Examples: > :xnoremap <CR> diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index b62ed557e4..b679b64bf6 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -2831,13 +2831,13 @@ static void f_getregion(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) int fnum = -1; // NOTE: var2fpos() returns static pointer. pos_T *fp = var2fpos(&argvars[0], true, &fnum, false); - if (fp == NULL) { + if (fp == NULL || (fnum >= 0 && fnum != curbuf->b_fnum)) { return; } pos_T p1 = *fp; fp = var2fpos(&argvars[1], true, &fnum, false); - if (fp == NULL) { + if (fp == NULL || (fnum >= 0 && fnum != curbuf->b_fnum)) { return; } pos_T p2 = *fp; diff --git a/test/old/testdir/test_visual.vim b/test/old/testdir/test_visual.vim index 084d64ba07..88f587a83a 100644 --- a/test/old/testdir/test_visual.vim +++ b/test/old/testdir/test_visual.vim @@ -1716,7 +1716,16 @@ func Test_visual_getregion() call assert_fails(':echo "."->getregion([],"V")', 'E1174:') call assert_fails(':echo "."->getregion("$", {})', 'E1174:') call assert_fails(':echo [0, 1, 1, 0]->getregion("$", "v")', 'E1174:') - + " using a mark in another buffer + new + let newbuf = bufnr() + call setline(1, range(10)) + normal! GmA + wincmd p + call assert_equal([newbuf, 10, 1, 0], getpos("'A")) + call assert_equal([], getregion(".", "'A", 'v')) + call assert_equal([], getregion("'A", ".", 'v')) + exe newbuf .. 'bwipe!' bwipe! " Selection in starts or ends in the middle of a multibyte character |