Skip to content

Commit 015234e

Browse files
authored
#837 find file symlinks fixes (#1093)
1 parent 1352cb3 commit 015234e

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

lua/nvim-tree/actions/find-file.lua

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
local uv = vim.loop
12
local view = require "nvim-tree.view"
23
local utils = require "nvim-tree.utils"
34
local renderer = require "nvim-tree.renderer"
@@ -7,23 +8,38 @@ local M = {}
78

89
local running = {}
910

11+
---Find a path in the tree, expand it and focus it
12+
---@param fname string full path
1013
function M.fn(fname)
1114
if running[fname] or not core.get_explorer() then
1215
return
1316
end
1417
running[fname] = true
1518

19+
-- always match against the real path
20+
local fname_real = uv.fs_realpath(fname)
21+
if not fname_real then
22+
return
23+
end
24+
1625
local i = view.is_root_folder_visible() and 1 or 0
1726
local tree_altered = false
1827

1928
local function iterate_nodes(nodes)
2029
for _, node in ipairs(nodes) do
2130
i = i + 1
22-
if node.absolute_path == fname then
23-
return i
31+
32+
if not node.absolute_path or not uv.fs_stat(node.absolute_path) then
33+
break
2434
end
2535

26-
local path_matches = node.nodes and vim.startswith(fname, node.absolute_path .. utils.path_separator)
36+
-- match against node absolute and link, as symlinks themselves will differ
37+
if node.absolute_path == fname_real or node.link_to == fname_real then
38+
return i
39+
end
40+
local abs_match = vim.startswith(fname_real, node.absolute_path .. utils.path_separator)
41+
local link_match = node.link_to and vim.startswith(fname_real, node.link_to .. utils.path_separator)
42+
local path_matches = node.nodes and (abs_match or link_match)
2743
if path_matches then
2844
if not node.open then
2945
node.open = true

0 commit comments

Comments
 (0)