From 0a7c24b675ab75dab8c36f2a326d274ad66b7166 Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Sun, 10 Dec 2023 10:13:22 +1100 Subject: [PATCH] fix(#2568): hijack_cursor positions at top grouped node (#2569) Co-authored-by: Azad <49314270+Akmadan23@users.noreply.github.com> --- lua/nvim-tree.lua | 1 + lua/nvim-tree/utils.lua | 11 +++++------ 2 files changed, 6 insertions(+), 6 deletions(-) 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