3rd / image.nvim

🖼️ Bringing images to Neovim.
MIT License
812 stars 35 forks source link

sticky images #100

Closed JJJHolscher closed 6 months ago

JJJHolscher commented 6 months ago

When changing buffer (I type :e other.file), the image disappears, but I want it to stay there. I currently fix this by rerendering it on an autocommand, but this results in an unappealing flicker whenever I change buffers.

This might also resolve the issue where I need to time my image rendering a bit after buffer switching, lest it gets wiped after showing for a single frame. Though that is not the main thing I'm asking for here.

See here for the code that gets this behavior:

local img_api = require("image")
local image = img_api.from_file("/path/to/image.png")

local render = function()
    local width = vim.fn.winwidth(0) - 82
    local height = vim.fn.winheight(0)
    image:render({ x = 82, y = 0, width = width, height = height })
end
render()

vim.api.nvim_create_autocmd("BufWinEnter",
    { callback = render })
vim.api.nvim_create_autocmd("VimResized",
    { callback = render })

ugly hotfix to deal with images disappearing after 1 frame:

local redraw_timer = vim.loop.new_timer()

local render = function()
    local width = vim.fn.winwidth(0) - 82
    local height = vim.fn.winheight(0)

    redraw_timer:start(50, 0, function()
        image:render({ x = 82, y = 0, width = width, height = height })
    end)
end
3rd commented 6 months ago

Definitely a bug, the image should stay on unless attached to a buffer. Will look into it!

Edit: wohoo issue #100

3rd commented 6 months ago

It was a bug in the logic handling clearing the images on window close, fixed now.

JJJHolscher commented 6 months ago

Thanks, this indeed fixed it for me.