mirror of
https://github.com/neovim/neovim.git
synced 2026-06-19 02:01:17 +00:00
feat(pos): create a cursor position by using the current of a window
Problem: `vim.pos.cursor(vim.api.nvim_get_current_buf(win), vim.api.nvim_win_get_cursor(win))` is too verbose to create a cursor position of a window, but it is a common use case. Solution: Overload `vim.pos.cursor()`, so that it accepts `win` as an argument when `pos` is omitted.
This commit is contained in:
@@ -30,6 +30,15 @@ describe('vim.pos', function()
|
||||
eq(buf, pos[3])
|
||||
end)
|
||||
|
||||
it('creates a position from the window cursor', function()
|
||||
local pos, buf = exec_lua(function()
|
||||
vim.api.nvim_buf_set_lines(0, 0, -1, true, { 'first', 'second' })
|
||||
vim.api.nvim_win_set_cursor(0, { 2, 3 })
|
||||
return vim.pos.cursor(0), vim.api.nvim_get_current_buf()
|
||||
end)
|
||||
eq({ 1, 3, buf }, pos)
|
||||
end)
|
||||
|
||||
it('comparisons by overloaded operators', function()
|
||||
local buf = exec_lua(function()
|
||||
return vim.api.nvim_create_buf(false, true)
|
||||
|
||||
Reference in New Issue
Block a user