Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update PreviewImageNvimTree function to work with updated nvim-tree #20

Open
MarGustafsson opened this issue Oct 30, 2024 · 1 comment

Comments

@MarGustafsson
Copy link

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!

@bavo96
Copy link

bavo96 commented Nov 16, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants