#837 find file symlinks fixes (#1093)

This commit is contained in:
Alexander Courtis
2022-03-26 23:17:34 +11:00
committed by GitHub
parent 1352cb312c
commit 015234e032

View File

@@ -1,3 +1,4 @@
local uv = vim.loop
local view = require "nvim-tree.view" local view = require "nvim-tree.view"
local utils = require "nvim-tree.utils" local utils = require "nvim-tree.utils"
local renderer = require "nvim-tree.renderer" local renderer = require "nvim-tree.renderer"
@@ -7,23 +8,38 @@ local M = {}
local running = {} local running = {}
---Find a path in the tree, expand it and focus it
---@param fname string full path
function M.fn(fname) function M.fn(fname)
if running[fname] or not core.get_explorer() then if running[fname] or not core.get_explorer() then
return return
end end
running[fname] = true running[fname] = true
-- always match against the real path
local fname_real = uv.fs_realpath(fname)
if not fname_real then
return
end
local i = view.is_root_folder_visible() and 1 or 0 local i = view.is_root_folder_visible() and 1 or 0
local tree_altered = false local tree_altered = false
local function iterate_nodes(nodes) local function iterate_nodes(nodes)
for _, node in ipairs(nodes) do for _, node in ipairs(nodes) do
i = i + 1 i = i + 1
if node.absolute_path == fname then
return i if not node.absolute_path or not uv.fs_stat(node.absolute_path) then
break
end end
local path_matches = node.nodes and vim.startswith(fname, node.absolute_path .. utils.path_separator) -- match against node absolute and link, as symlinks themselves will differ
if node.absolute_path == fname_real or node.link_to == fname_real then
return i
end
local abs_match = vim.startswith(fname_real, node.absolute_path .. utils.path_separator)
local link_match = node.link_to and vim.startswith(fname_real, node.link_to .. utils.path_separator)
local path_matches = node.nodes and (abs_match or link_match)
if path_matches then if path_matches then
if not node.open then if not node.open then
node.open = true node.open = true