File tree Expand file tree Collapse file tree 1 file changed +19
-3
lines changed Expand file tree Collapse file tree 1 file changed +19
-3
lines changed Original file line number Diff line number Diff line change
1
+ local uv = vim .loop
1
2
local view = require " nvim-tree.view"
2
3
local utils = require " nvim-tree.utils"
3
4
local renderer = require " nvim-tree.renderer"
@@ -7,23 +8,38 @@ local M = {}
7
8
8
9
local running = {}
9
10
11
+ --- Find a path in the tree, expand it and focus it
12
+ --- @param fname string full path
10
13
function M .fn (fname )
11
14
if running [fname ] or not core .get_explorer () then
12
15
return
13
16
end
14
17
running [fname ] = true
15
18
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
+
16
25
local i = view .is_root_folder_visible () and 1 or 0
17
26
local tree_altered = false
18
27
19
28
local function iterate_nodes (nodes )
20
29
for _ , node in ipairs (nodes ) do
21
30
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
24
34
end
25
35
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 )
27
43
if path_matches then
28
44
if not node .open then
29
45
node .open = true
You can’t perform that action at this time.
0 commit comments