Skip to content

Commit 0d6eefd

Browse files
committed
fix: allow changing root to file`s parent directory and fix restrict_above_cwd config path
1 parent d5b8ead commit 0d6eefd

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

lua/nvim-tree/api.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ local notify = require("nvim-tree.notify")
1010

1111
local DirectoryNode = require("nvim-tree.node.directory")
1212
local FileLinkNode = require("nvim-tree.node.file-link")
13+
local FileNode = require("nvim-tree.node.file")
1314
local RootNode = require("nvim-tree.node.root")
1415
local UserDecorator = require("nvim-tree.renderer.decorator.user")
1516

@@ -160,6 +161,8 @@ end)
160161
Api.tree.change_root_to_node = wrap_node(function(node)
161162
if node.name == ".." or node:is(RootNode) then
162163
wrap_explorer("change_dir")("..")
164+
elseif node:is(FileNode) and node.parent ~= nil then
165+
wrap_explorer("change_dir")(node.parent:last_group_node().absolute_path)
163166
else
164167
node = node:as(DirectoryNode)
165168
if node then

lua/nvim-tree/explorer/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ end
716716
---@return boolean
717717
function Explorer:prevent_cwd_change(foldername)
718718
local is_same_cwd = foldername == self.absolute_path
719-
local is_restricted_above = config.restrict_above_cwd and foldername < vim.fn.getcwd(-1, -1)
719+
local is_restricted_above = config.actions.change_dir.restrict_above_cwd and foldername < vim.fn.getcwd(-1, -1)
720720
return is_same_cwd or is_restricted_above
721721
end
722722

0 commit comments

Comments
 (0)