Skip to content

fix(#2878): nowrapscan prevents move from root #2880

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lua/nvim-tree/actions/moves/item.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,15 @@ end
---@param what string type of status
---@param skip_gitignored boolean default false
local function move(where, what, skip_gitignored)
local node_cur = lib.get_node_at_cursor()
local first_node_line = core.get_nodes_starting_line()
local nodes_by_line = utils.get_nodes_by_line(core.get_explorer().nodes, first_node_line)
local iter_start, iter_end, iter_step, cur, first, nex

local cursor = lib.get_cursor_position()
if cursor and cursor[1] < first_node_line then
cur = cursor[1]
end

if where == "next" then
iter_start, iter_end, iter_step = first_node_line, #nodes_by_line, 1
elseif where == "prev" then
Expand All @@ -52,7 +56,7 @@ local function move(where, what, skip_gitignored)
first = line
end

if node == node_cur then
if cursor and line == cursor[1] then
cur = line
elseif valid and cur then
nex = line
Expand Down
22 changes: 15 additions & 7 deletions lua/nvim-tree/lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,33 @@ local M = {
target_winid = nil,
}

---@return Node|nil
function M.get_node_at_cursor()
---Cursor position as per vim.api.nvim_win_get_cursor
---@return integer[]|nil
function M.get_cursor_position()
if not core.get_explorer() then
return
end

local winnr = view.get_winnr()
if not winnr then
if not winnr or not vim.api.nvim_win_is_valid(winnr) then
return
end

local cursor = vim.api.nvim_win_get_cursor(winnr)
local line = cursor[1]
return vim.api.nvim_win_get_cursor(winnr)
end

---@return Node|nil
function M.get_node_at_cursor()
local cursor = M.get_cursor_position()
if not cursor then
return
end

if line == 1 and view.is_root_folder_visible(core.get_cwd()) then
if cursor[1] == 1 and view.is_root_folder_visible(core.get_cwd()) then
return { name = ".." }
end

return utils.get_nodes_by_line(core.get_explorer().nodes, core.get_nodes_starting_line())[line]
return utils.get_nodes_by_line(core.get_explorer().nodes, core.get_nodes_starting_line())[cursor[1]]
end

---Create a sanitized partial copy of a node, populating children recursively.
Expand Down
Loading