diff options
author | Aayush Ojha <aayushojha12@gmail.com> | 2023-10-06 05:44:50 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-06 05:44:50 -0700 |
commit | 5db076c7ccfef6732516074252ac4b21b12fc629 (patch) | |
tree | 0d32814f718065e91c1965850dd9f7771e3e7a8d | |
parent | 01374446af9663dde5c60a7067775418c2cbf135 (diff) | |
download | rneovim-5db076c7ccfef6732516074252ac4b21b12fc629.tar.gz rneovim-5db076c7ccfef6732516074252ac4b21b12fc629.tar.bz2 rneovim-5db076c7ccfef6732516074252ac4b21b12fc629.zip |
fix(lua): vim.region on linewise selection #25467
fixes #18155
-rw-r--r-- | runtime/lua/vim/_editor.lua | 3 | ||||
-rw-r--r-- | test/functional/lua/vim_spec.lua | 8 |
2 files changed, 11 insertions, 0 deletions
diff --git a/runtime/lua/vim/_editor.lua b/runtime/lua/vim/_editor.lua index 1ba7d6163d..bbe93bfbc8 100644 --- a/runtime/lua/vim/_editor.lua +++ b/runtime/lua/vim/_editor.lua @@ -548,6 +548,9 @@ function vim.region(bufnr, pos1, pos2, regtype, inclusive) else c2 = #bufline + 1 end + elseif regtype == 'V' then -- linewise selection, always return whole line + c1 = 0 + c2 = -1 else c1 = (l == pos1[1]) and pos1[2] or 0 c2 = (l == pos2[1]) and (pos2[2] + (inclusive and 1 or 0)) or -1 diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua index bd3d8f5247..c69990d84b 100644 --- a/test/functional/lua/vim_spec.lua +++ b/test/functional/lua/vim_spec.lua @@ -2401,6 +2401,14 @@ describe('lua stdlib', function() insert([[αα]]) eq({0,5}, exec_lua[[ return vim.region(0,{0,0},{0,4},'3',true)[0] ]]) end) + it('linewise', function() + insert(dedent( [[ + text tααt tααt text + text tαxt txtα tex + text tαxt tαxt + ]])) + eq({0,-1}, exec_lua[[ return vim.region(0,{1,5},{1,14},'V',true)[1] ]]) + end) it('getpos() input', function() insert('getpos') eq({0,6}, exec_lua[[ return vim.region(0,{0,0},'.','v',true)[0] ]]) |