vim-patch:9.1.1407: Can't use getpos('v') in OptionSet when using setbufvar() (#34177)

Problem:  Can't use getpos('v') in OptionSet when using setbufvar().
Solution: Don't reset Visual selection when switching to the same
          buffer (zeertzjq).

closes: vim/vim#17373

5717ee33db
(cherry picked from commit bd01bd6564)
This commit is contained in:
zeertzjq
2025-05-26 06:51:15 +08:00
committed by github-actions[bot]
parent 5e0ef6afc7
commit d1ca551983
4 changed files with 63 additions and 3 deletions

View File

@@ -11,6 +11,30 @@ local eq = t.eq
before_each(clear)
local function expected_empty()
eq({}, api.nvim_get_vvar('errors'))
end
-- oldtest: Test_get_Visual_selection_in_curbuf_autocmd()
it('autocmd can get Visual selection when using setbufvar() on curbuf', function()
n.exec([[
new
autocmd OptionSet list let b:text = getregion(getpos('.'), getpos('v'))
call setline(1, 'foo bar baz')
normal! gg0fbvtb
setlocal list
call assert_equal(['bar '], b:text)
exe "normal! \<Esc>"
normal! v0
call setbufvar('%', '&list', v:false)
call assert_equal(['foo bar '], b:text)
exe "normal! \<Esc>"
]])
expected_empty()
end)
-- oldtest: Test_autocmd_invalidates_undo_on_textchanged()
it('no E440 in quickfix window when autocommand invalidates undo', function()
write_file(

View File

@@ -3930,6 +3930,17 @@ stack traceback:
]]
)
end)
it('can get Visual selection in current buffer #34162', function()
insert('foo bar baz')
feed('gg0fbvtb')
local text = exec_lua([[
return vim.api.nvim_buf_call(0, function()
return vim.fn.getregion(vim.fn.getpos('.'), vim.fn.getpos('v'))
end)
]])
eq({ 'bar ' }, text)
end)
end)
describe('vim.api.nvim_win_call', function()