Skip to content

Commit 762968a

Browse files
committed
fix(#2878): nowrapscan prevents move from root
1 parent 2104786 commit 762968a

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

lua/nvim-tree/actions/moves/item.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ local function move(where, what, skip_gitignored)
3838
local nodes_by_line = utils.get_nodes_by_line(core.get_explorer().nodes, first_node_line)
3939
local iter_start, iter_end, iter_step, cur, first, nex
4040

41+
local cursor = lib.get_cursor_position()
42+
if cursor and cursor[1] < first_node_line then
43+
cur = cursor[1]
44+
end
45+
4146
if where == "next" then
4247
iter_start, iter_end, iter_step = first_node_line, #nodes_by_line, 1
4348
elseif where == "prev" then

lua/nvim-tree/lib.lua

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,33 @@ local M = {
1515
target_winid = nil,
1616
}
1717

18-
---@return Node|nil
19-
function M.get_node_at_cursor()
18+
---Cursor position as per vim.api.nvim_win_get_cursor
19+
---@return integer[]|nil
20+
function M.get_cursor_position()
2021
if not core.get_explorer() then
2122
return
2223
end
2324

2425
local winnr = view.get_winnr()
25-
if not winnr then
26+
if not winnr or not vim.api.nvim_win_is_valid(winnr) then
2627
return
2728
end
2829

29-
local cursor = vim.api.nvim_win_get_cursor(winnr)
30-
local line = cursor[1]
30+
return vim.api.nvim_win_get_cursor(winnr)
31+
end
32+
33+
---@return Node|nil
34+
function M.get_node_at_cursor()
35+
local cursor = M.get_cursor_position()
36+
if not cursor then
37+
return
38+
end
3139

32-
if line == 1 and view.is_root_folder_visible(core.get_cwd()) then
40+
if cursor[1] == 1 and view.is_root_folder_visible(core.get_cwd()) then
3341
return { name = ".." }
3442
end
3543

36-
return utils.get_nodes_by_line(core.get_explorer().nodes, core.get_nodes_starting_line())[line]
44+
return utils.get_nodes_by_line(core.get_explorer().nodes, core.get_nodes_starting_line())[cursor[1]]
3745
end
3846

3947
---Create a sanitized partial copy of a node, populating children recursively.

0 commit comments

Comments
 (0)