Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
6b1f5b8
chore: moving root action dir-up to explorer class
Uanela Dec 9, 2025
41585a8
chore(explorer): moving requires to top level
Uanela Dec 19, 2025
a12890c
wip(explorer): moved all change-dir functions to explorer class
Uanela Dec 27, 2025
fd5ee1d
wip(explorer): rename M.current_tab to self.current_tab
Uanela Dec 27, 2025
85b621b
chore(explorer): move change_dir root action to explorer and replace …
Uanela Dec 27, 2025
896e629
refactor(explorer): changing _foldername to folder_name
Uanela Dec 27, 2025
2ea9992
merge with master
Uanela Dec 27, 2025
5084dd4
wip(explorer): rename expand method to expand_dir_node and all places…
Uanela Dec 27, 2025
d5b8ead
wip(explorer): mark private methods and remove add_profiling_to method
Uanela Dec 28, 2025
0d6eefd
fix: allow changing root to file`s parent directory and fix restrict_…
Uanela Dec 28, 2025
db36b04
refactor(api): moving change_root_to_node to Explorer:change_dir_to_node
Uanela Dec 28, 2025
189c036
Merge branch 'master' of https://github.com/uanela/nvim-tree.lua into…
Uanela Jan 22, 2026
195f924
fix(explorer): get new explorer before redrawing on <C-]>
Uanela Jan 22, 2026
fd300ed
docs(explorer): adding link to PR discussion for more context
Uanela Jan 22, 2026
4995699
fix(explorer): correctly check config.actions.change_dir for change_d…
Uanela Jan 22, 2026
986c79a
fix: correctly pass explorer as first arg when calling explorer metho…
Uanela Jan 22, 2026
e4f7cc5
fix: correctly pass args to change_dir
Uanela Jan 22, 2026
0933b46
fix: check for explorer before force_dirchange in open_on_directory
Uanela Jan 23, 2026
47c8a7e
Merge branch 'master' into moving-change-dir-to-explorer
Uanela Jan 23, 2026
b97299e
fix: check if force_dirchange should call core.init
Uanela Jan 23, 2026
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
29 changes: 23 additions & 6 deletions lua/nvim-tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ local M = {
init_root = "",
}

--- Helper function to execute some explorer method safely
---@param fn string # key of explorer
---@param ... any|nil
---@return function|nil
local function explorer_fn(fn, ...)
local explorer = core.get_explorer()
if explorer then
return explorer[fn](explorer, ...)
end
end

--- Update the tree root to a directory or the directory containing
---@param path string relative or absolute
---@param bufnr number|nil
Expand Down Expand Up @@ -47,7 +58,7 @@ function M.change_root(path, bufnr)
-- test if in vim_cwd
if utils.path_relative(path, vim_cwd) ~= path then
if vim_cwd ~= cwd then
actions.root.change_dir.fn(vim_cwd)
explorer_fn("change_dir", vim_cwd)
end
return
end
Expand All @@ -58,19 +69,19 @@ function M.change_root(path, bufnr)

-- otherwise test M.init_root
if _config.prefer_startup_root and utils.path_relative(path, M.init_root) ~= path then
actions.root.change_dir.fn(M.init_root)
explorer_fn("change_dir", M.init_root)
return
end
-- otherwise root_dirs
for _, dir in pairs(_config.root_dirs) do
dir = vim.fn.fnamemodify(dir, ":p")
if utils.path_relative(path, dir) ~= path then
actions.root.change_dir.fn(dir)
explorer_fn("change_dir", dir)
return
end
end
-- finally fall back to the folder containing the file
actions.root.change_dir.fn(vim.fn.fnamemodify(path, ":p:h"))
explorer_fn("change_dir", vim.fn.fnamemodify(path, ":p:h"))
end

function M.tab_enter()
Expand Down Expand Up @@ -110,7 +121,13 @@ function M.open_on_directory()
return
end

actions.root.change_dir.force_dirchange(bufname, true)

local explorer = core.get_explorer()
if not explorer then
core.init(bufname)
end

explorer_fn("force_dirchange", bufname, true, false)
end

---@return table
Expand All @@ -134,7 +151,7 @@ end
---@param name string|nil
function M.change_dir(name)
if name then
actions.root.change_dir.fn(name)
explorer_fn("change_dir", name)
end

if _config.update_focused_file.update_root.enable then
Expand Down
2 changes: 1 addition & 1 deletion lua/nvim-tree/actions/finders/find-file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function M.fn(path)
dir.open = true
end
if #dir.nodes == 0 then
core.get_explorer():expand(dir)
core.get_explorer():expand_dir_node(dir)
if dir.group_next and incremented_line then
line = line - 1
end
Expand Down
2 changes: 0 additions & 2 deletions lua/nvim-tree/actions/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ M.finders = require("nvim-tree.actions.finders")
M.fs = require("nvim-tree.actions.fs")
M.moves = require("nvim-tree.actions.moves")
M.node = require("nvim-tree.actions.node")
M.root = require("nvim-tree.actions.root")
M.tree = require("nvim-tree.actions.tree")

function M.setup(opts)
M.fs.setup(opts)
M.node.setup(opts)
M.root.setup(opts)
M.tree.setup(opts)
end

Expand Down
105 changes: 0 additions & 105 deletions lua/nvim-tree/actions/root/change-dir.lua

This file was deleted.

9 changes: 0 additions & 9 deletions lua/nvim-tree/actions/root/init.lua

This file was deleted.

4 changes: 2 additions & 2 deletions lua/nvim-tree/actions/tree/modifiers/expand.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ local function expand(node)
node = node:last_group_node()
node.open = true
if #node.nodes == 0 then
core.get_explorer():expand(node)
core.get_explorer():expand_dir_node(node)
end
end

Expand Down Expand Up @@ -66,7 +66,7 @@ local function should_expand(expansion_count, node, should_descend)

if not dir.open and should_descend(expansion_count, node) then
if #node.nodes == 0 then
core.get_explorer():expand(dir) -- populate node.group_next
core.get_explorer():expand_dir_node(dir) -- populate node.group_next
end

if dir.group_next then
Expand Down
21 changes: 2 additions & 19 deletions lua/nvim-tree/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ local keymap = require("nvim-tree.keymap")
local notify = require("nvim-tree.notify")

local DirectoryNode = require("nvim-tree.node.directory")
local FileNode = require("nvim-tree.node.file")
local FileLinkNode = require("nvim-tree.node.file-link")
local RootNode = require("nvim-tree.node.root")
local UserDecorator = require("nvim-tree.renderer.decorator.user")
Expand Down Expand Up @@ -158,23 +157,7 @@ Api.tree.change_root = wrap(function(...)
require("nvim-tree").change_dir(...)
end)

Api.tree.change_root_to_node = wrap_node(function(node)
if node.name == ".." or node:is(RootNode) then
actions.root.change_dir.fn("..")
return
end

if node:is(FileNode) and node.parent ~= nil then
actions.root.change_dir.fn(node.parent:last_group_node().absolute_path)
return
end

if node:is(DirectoryNode) then
actions.root.change_dir.fn(node:last_group_node().absolute_path)
return
end
end)

Api.tree.change_root_to_node = wrap_node(wrap_explorer("change_dir_to_node"))
Api.tree.change_root_to_parent = wrap_node(wrap_explorer("dir_up"))
Api.tree.get_node_under_cursor = wrap_explorer("get_node_at_cursor")
Api.tree.get_nodes = wrap_explorer("get_nodes")
Expand Down Expand Up @@ -281,7 +264,7 @@ local function open_or_expand_or_dir_up(mode, toggle_group)
local dir = node:as(DirectoryNode)

if root or node.name == ".." then
actions.root.change_dir.fn("..")
wrap_explorer("change_dir")("..")
elseif dir then
dir:expand_or_collapse(toggle_group)
elseif not toggle_group then
Expand Down
Loading
Loading