fix(run-command): handle current directory node (#1046)
Handle the node representing the current directory (the topmost node in the nvim-tree window). That node does not have the `absolute_path` set. Use `TreeExplorer.cwd` instead, similar to the logic in `change-dir`.
This commit is contained in:
committed by
GitHub
parent
a3f256dc1b
commit
ac858a28a2
@@ -1,8 +1,21 @@
|
||||
local utils = require("nvim-tree.utils")
|
||||
|
||||
local M = {}
|
||||
|
||||
---Retrieves the absolute path to the node.
|
||||
---Safely handles the node representing the current directory
|
||||
---(the topmost node in the nvim-tree window)
|
||||
local function get_node_path(node)
|
||||
if node.name == ".." then
|
||||
return utils.path_remove_trailing(TreeExplorer.cwd)
|
||||
else
|
||||
return node.absolute_path
|
||||
end
|
||||
end
|
||||
|
||||
function M.run_file_command(node)
|
||||
vim.api.nvim_input(": " .. node.absolute_path .. "<Home>")
|
||||
local node_path = get_node_path(node)
|
||||
vim.api.nvim_input(": " .. node_path .. "<Home>")
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
|
||||
Reference in New Issue
Block a user