Skip to content

Commit

Permalink
fix: rerender images below the current one after adding extmark
Browse files Browse the repository at this point in the history
  • Loading branch information
3rd committed Jul 3, 2023
1 parent 3dbb7f4 commit 093ef13
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
11 changes: 8 additions & 3 deletions lua/image/image.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ local from_file = function(path, options, state)
if geometry then instance.geometry = vim.tbl_deep_extend("force", instance.geometry, geometry) end

-- utils.debug(("\n\n---------------- %s ----------------"):format(instance.id))
local ok = renderer.render(instance, state)
local was_rendered = renderer.render(instance, state)
-- utils.debug("render result", instance.id, ok)

-- virtual padding
Expand All @@ -74,7 +74,7 @@ local from_file = function(path, options, state)

local previous_extmark = buf_extmark_map[instance.buffer .. ":" .. row]

if not ok and previous_extmark then
if not was_rendered and previous_extmark then
state.backend.clear(instance.id, true)
vim.api.nvim_buf_del_extmark(instance.buffer, state.extmarks_namespace, previous_extmark.id)
buf_extmark_map[instance.buffer .. ":" .. row] = nil
Expand All @@ -86,7 +86,7 @@ local from_file = function(path, options, state)
vim.api.nvim_buf_del_extmark(instance.buffer, state.extmarks_namespace, previous_extmark.id)
end

if ok then
if was_rendered then
local text = string.rep(" ", width)
local filler = {}
for _ = 0, height - 1 do
Expand All @@ -97,6 +97,11 @@ local from_file = function(path, options, state)
virt_lines = filler,
})
buf_extmark_map[instance.buffer .. ":" .. row] = { id = numerical_id, height = height }

-- rerender any images that are below this one
for _, image in pairs(state.images) do
if image.buffer == instance.buffer and image.geometry.y > instance.geometry.y then image.render() end
end
end
end
end
Expand Down
3 changes: 2 additions & 1 deletion lua/image/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ api.setup = function(options)
-- setup namespaces
state.extmarks_namespace = vim.api.nvim_create_namespace("image.nvim")

-- handle folds / scroll extra
---@type table<number, { topline: number, botline: number, bufnr: number, height: number; folded_lines: number }>
local window_history = {}
vim.api.nvim_set_decoration_provider(state.extmarks_namespace, {
Expand Down Expand Up @@ -158,7 +159,7 @@ api.setup = function(options)
end,
})

-- rerender on scroll/fold
-- rerender on scroll
vim.api.nvim_create_autocmd("WinScrolled", {
group = group,
callback = function(au)
Expand Down

0 comments on commit 093ef13

Please sign in to comment.