Skip to content

Commit fe466d3

Browse files
committed
get_node_at_cursor returns explorer (root) node instead of { name = '..' }
1 parent f91975e commit fe466d3

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Diff for: lua/nvim-tree/lib.lua

+8-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ local M = {
1414
}
1515

1616
---Cursor position as per vim.api.nvim_win_get_cursor
17+
---nil on no explorer or invalid view win
1718
---@return integer[]|nil
1819
function M.get_cursor_position()
1920
if not core.get_explorer() then
@@ -30,16 +31,21 @@ end
3031

3132
---@return Node|nil
3233
function M.get_node_at_cursor()
34+
local explorer = core.get_explorer()
35+
if not explorer then
36+
return
37+
end
38+
3339
local cursor = M.get_cursor_position()
3440
if not cursor then
3541
return
3642
end
3743

3844
if cursor[1] == 1 and view.is_root_folder_visible(core.get_cwd()) then
39-
return { name = ".." }
45+
return explorer
4046
end
4147

42-
return utils.get_nodes_by_line(core.get_explorer().nodes, core.get_nodes_starting_line())[cursor[1]]
48+
return utils.get_nodes_by_line(explorer.nodes, core.get_nodes_starting_line())[cursor[1]]
4349
end
4450

4551
---Api.tree.get_nodes

0 commit comments

Comments
 (0)