Skip to content

#837 find file symlinks fixes #1093

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

Merged
merged 6 commits into from
Mar 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions lua/nvim-tree/actions/find-file.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
local uv = vim.loop
local view = require "nvim-tree.view"
local utils = require "nvim-tree.utils"
local renderer = require "nvim-tree.renderer"
Expand All @@ -7,23 +8,38 @@ local M = {}

local running = {}

---Find a path in the tree, expand it and focus it
---@param fname string full path
function M.fn(fname)
if running[fname] or not core.get_explorer() then
return
end
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 tree_altered = false

local function iterate_nodes(nodes)
for _, node in ipairs(nodes) do
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

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 not node.open then
node.open = true
Expand Down