fix(image): better image position caluclation. Closes #1268

This commit is contained in:
Folke Lemaitre 2025-02-18 22:02:58 +01:00
parent 7e0ad4d4e6
commit 5c0607e31a
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040

View file

@ -123,12 +123,16 @@ function M.find(buf, from, to)
assert(ctx.pos, "no image node")
local range = vim.treesitter.get_range(ctx.pos.node, buf, ctx.pos.meta)
local lines = vim.api.nvim_buf_get_lines(buf, range[1], range[4] + 1, false)
while #lines > 0 and vim.trim(lines[#lines]) == "" do
table.remove(lines)
end
---@type snacks.image.match
local img = {
ext = meta["image.ext"],
id = ctx.pos.node:id(),
pos = {
range[1] == range[4] and (range[1] + 1) or (range[4] + 1),
range[1] + #lines,
math.min(range[2], range[5]),
},
}