image_preview.nvim icon indicating copy to clipboard operation
image_preview.nvim copied to clipboard

update `PreviewImageNvimTree` function to work with updated nvim-tree

Open MarGustafsson opened this issue 1 year ago • 3 comments

Hi, i installed the plugin and noticed that i got only errors when trying it out in nvim-tree.

After some digging through the nvim-tree docs, I noticed that the command get_node_at_cursor() was no longer present, however there was a command called get_node_under_cursor() which seemed to do the same thing.

I tested it out in my local keymaps file just to see if it would work, and it did, here is the example of what i tested:

nnoremap("<leader>P", function ()
  local nvimtree = require("nvim-tree.api")
  local img_preview = require("image_preview")
  local path = nvimtree.tree.get_node_under_cursor().absolute_path
  img_preview.PreviewImage(path)
end, { desc = "Preview image under cursor (NvimTree)" })

nnoremap is just a personal helper that sets up the keybind for normal mode btw.

So i think the plugin should work for nvim-tree again with just 2 changes, here is what i think the PreviewImageNvimTree function should look like instead:

function M.PreviewImageNvimTree()
-  local use, imported = pcall(require, "nvim-tree.lib")
+  local use, imported = pcall(require, "nvim-tree.api")
    if use then
-      local absolutePath = imported.get_node_at_cursor().absolute_path
+      local absolutePath = imported.tree.get_node_under_cursor().absolute_path
        M.PreviewImage(absolutePath)
    else
        return ''
    end
end

I didn't have time to make a proper pull request, but if you ever get to it i hope this issue helps!

MarGustafsson avatar Oct 30 '24 09:10 MarGustafsson

I have tried your solution but the image still doesn't show in the terminal. Your fix did get the correct node, but it seems like the wezterm doesn't show image into buffer. I'm currently in macOS. Edit: I am able to open image in Ubuntu, but still can't open in macOS using @MarGustafsson's solution.

bavo96 avatar Nov 16 '24 06:11 bavo96

I can confirm, not working on macos with "WezTerm" it is not about "get_node_under_cursor" I wrote the absoluePath hardcoded, it finds the file but can't show.

kervanaslan avatar Dec 24 '24 05:12 kervanaslan

simply pres "s" on the file tree it will open it with macos preview screen.

kervanaslan avatar Dec 24 '24 06:12 kervanaslan