diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index ce9837e9..61cdf413 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -124,6 +124,7 @@ function M.place_cursor_on_node() if not node or node.name == ".." then return end + node = utils.get_parent_of_group(node) local line = vim.api.nvim_get_current_line() local cursor = vim.api.nvim_win_get_cursor(0) diff --git a/lua/nvim-tree/utils.lua b/lua/nvim-tree/utils.lua index effdab46..fe1b2481 100644 --- a/lua/nvim-tree/utils.lua +++ b/lua/nvim-tree/utils.lua @@ -149,12 +149,11 @@ function M.get_node_from_path(path) :iterate() end ---- Get the highest parent of grouped nodes ----@param node_ Node ----@return table -function M.get_parent_of_group(node_) - local node = node_ - while node.parent and node.parent.group_next do +---Get the highest parent of grouped nodes +---@param node Node +---@return Node node or parent +function M.get_parent_of_group(node) + while node and node.parent and node.parent.group_next do node = node.parent end return node