mikavilpas / yazi.nvim

A Neovim Plugin for the yazi terminal file manager
MIT License
214 stars 7 forks source link

Don't show image preview when open inside neovim #112

Closed minhtien3297 closed 2 weeks ago

minhtien3297 commented 3 weeks ago

When opened inside neovim, the image preview just doesn't work

Screenshot 2024-06-12 at 3 52 49 PM

This is when open outside of neovim

Screenshot 2024-06-12 at 3 51 42 PM

mikavilpas commented 3 weeks ago

I have this issue myself. I looked into it a while ago and I think this is not supported in neovim's embedded terminal yet.

I don't know if this can be resolved until support is added. Let's keep this open to track the status as well as any additional findings and ideas.

daUnknownCoder commented 3 weeks ago

@mikavilpas buddy check this out: https://new.reddit.com/r/neovim/comments/1dcjuxc/simplyfilenvim_now_can_use_3rdimagenvim_to/

might be able to steal 😉 some code

mikavilpas commented 3 weeks ago

Ok, nice find - that was fast 😄 ! I think that might work nicely, but one issue remains: in neovim, we don't yet know what is being previewed in yazi.

This is actually a neovim specific limitation and can be worked around with e.g. my proposal at https://github.com/sxyazi/yazi/pull/1004, which would add the ability to read events from the embedded yazi process in real time. Currently we can only read them after yazi has closed.

So it would work like this:

sequenceDiagram
  neovim->>yazi: open yazi
  yazi->>neovim: file hovered event: /path/to/image.png
  neovim-->neovim: preview image
  yazi->>neovim: file hovered event: /path/to/file.txt
  neovim-->neovim: 🔎 not an image, don't preview anything
mikavilpas commented 3 weeks ago

I also wonder if this would work if yazi were configured to use https://github.com/jstkdng/ueberzugpp with yazi. I haven't tried this out, so it might be subject to the same neovim terminal limitation which causes images not to show.

daUnknownCoder commented 3 weeks ago

we don't yet know what is being previewed in yazi.

we can check the filetype? restrict the config to jpg, png, ...

mikavilpas commented 3 weeks ago

The issue is not yet knowing the name of the file that is hovered in yazi.

daUnknownCoder commented 3 weeks ago

I also wonder if this would work if yazi were configured to use https://github.com/jstkdng/ueberzugpp with yazi. I haven't tried this out, so it might be subject to the same neovim terminal limitation which causes images not to show.

https://yazi-rs.github.io/docs/configuration/yazi/#preview.ueberzug_scale

mikavilpas commented 3 weeks ago

Want to do an experiment with yazi + ueberzugpp + yazi.nvim to see if it works with this configuration? 🙂

daUnknownCoder commented 3 weeks ago

Want to do an experiment with yazi + ueberzugpp + yazi.nvim to see if it works with this configuration? 🙂

wait what? it already works there's no need for anything to be done 🙃, i havent updated, i dont use image.nvim

[!IMPORTANT] we have to pass something to the main config of yazi for the ueberzug offset (~/.config/yazi/yazi.toml)

[preview]
ueberzug_offset = [7.5,1,0,0]

[!IMPORTANT] this ⬆️ is what i configured for correct display of image, and it might be different for different people, as u might see the below images, the ueberzug offset is messed up ...

opts = {
    floating_window_scaling_factor = 1,
}

image

opts = {
    floating_window_scaling_factor = 0.8,
}

image

direct yazi window: image

mikavilpas commented 3 weeks ago

Oh, nice! Excellent work!

daUnknownCoder commented 3 weeks ago

Oh, nice! Excellent work!

ok i didnt do anything, my ueberzug wasnt working (i hadnt updated it for a while) :p

sxyazi commented 2 weeks ago

Regarding Yazi's behavior in Neovim: https://yazi-rs.github.io/docs/image-preview#neovim

mikavilpas commented 2 weeks ago

Awesome - thanks for the link!