Closed eyalk11 closed 10 months ago
Fix (thanks chatgpt)
local function get_visual()
local _, ls, cs = unpack(vim.fn.getpos('v'))
local _, le, ce = unpack(vim.fn.getpos('.'))
if ls > le or (ls == le and cs > ce) then
ls, cs, le, ce = le, ce, ls, cs
end
return vim.api.nvim_buf_get_text(0, ls - 1, cs - 1, le - 1, ce, {})
end
I just ran into this bug myself and came here to report it.
I fixed it locally like this:
local function get_visual()
local _, ls, cs = unpack(vim.fn.getpos('v'))
local _, le, ce = unpack(vim.fn.getpos('.'))
ls, le = math.min(ls, le), math.max(ls, le)
cs, ce = math.min(cs, ce), math.max(cs, ce)
return vim.api.nvim_buf_get_text(0, ls - 1, cs - 1, le - 1, ce, {})
end
If you start from the end and extend the visual selection, your script gets confused,