3rd / image.nvim

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

[bug] removing and adding image in buffer while images are displayed in a split #120

Closed benlubas closed 5 months ago

benlubas commented 5 months ago

Really specific scenario, but it's something that breaks a feature I want to add to molten.

The overview goes like this: if there's an image in your buffer, and a split buffer with other images, and you clear the image in your buffer and then rerender it very quickly, two images will show up (along with artifacts sometimes) where there should be one.

Video

https://github.com/3rd/image.nvim/assets/56943754/1a55ecf0-9cbb-490f-859b-6641a9b626cb

Reproduction Steps

  1. Open the provided file, and place a path to a local image in the file_path variable name
  2. source the file, close the split, source the file again, you should see images in the split and in the "main" window
  3. with cursor in the "main" window press <leader>M (a keymap that will unrender the image in the main buffer and immediately replace it with another image)
  4. You should see the images are duplicated
    
    local file_path = "/Users/benlubas/Downloads/neovim.png"

local content = [[

Hello World

I'm going to place an image below here via the api

other lines ]]

vim.schedule(function() local image = require("image") local img local original_win = vim.api.nvim_get_current_win() local original_buf = vim.api.nvim_get_current_buf() local buf = vim.api.nvim_create_buf(false, true) vim.api.nvim_buf_set_lines(buf, 0, -1, true, vim.split(content, "\n")) vim.api.nvim_buf_set_option(buf, "filetype", "markdown") vim.cmd("vs") vim.api.nvim_set_current_buf(buf)

image .from_file(file_path, { y = 3, with_virtual_padding = true, buffer = buf, window = vim.api.nvim_get_current_win(), }) :render() image .from_file(file_path, { y = 5, with_virtual_padding = true, buffer = buf, window = vim.api.nvim_get_current_win(), }) :render()

img = image .from_file(file_path, { y = 15, with_virtual_padding = true, buffer = original_buf, window = original_win, }) img:render() vim.keymap.set("n", "M", function() img:clear() img = image .from_file(file_path, { y = 15, with_virtual_padding = true, buffer = original_buf, window = original_win, }) img:render() end) end)

benlubas commented 5 months ago

I'm pretty sure this setup is just rending two images on top of eachother and then they're getting split.

I'm also able to reproduce this now, independent of the split window/image in the split window. I'm not sure what was causing that behavior for me yesterday. Maybe just unfortunate luck