Skip to content

Commit 0992969

Browse files
committed
move lib.get_cursor_position to Explorer
1 parent 8331a24 commit 0992969

File tree

3 files changed

+21
-19
lines changed

3 files changed

+21
-19
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,16 @@ end
3434
---@param what string type of status
3535
---@param skip_gitignored boolean default false
3636
local function move(where, what, skip_gitignored)
37+
local explorer = core.get_explorer()
38+
if not explorer then
39+
return
40+
end
41+
3742
local first_node_line = core.get_nodes_starting_line()
38-
local nodes_by_line = utils.get_nodes_by_line(core.get_explorer().nodes, first_node_line)
43+
local nodes_by_line = utils.get_nodes_by_line(explorer.nodes, first_node_line)
3944
local iter_start, iter_end, iter_step, cur, first, nex
4045

41-
local cursor = lib.get_cursor_position()
46+
local cursor = explorer:get_cursor_position()
4247
if cursor and cursor[1] < first_node_line then
4348
cur = cursor[1]
4449
end

lua/nvim-tree/explorer/init.lua

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,19 @@ function Explorer:reload_git()
374374
event_running = false
375375
end
376376

377+
---Cursor position as per vim.api.nvim_win_get_cursor
378+
---nil on no explorer or invalid view win
379+
---@return integer[]|nil
380+
function Explorer:get_cursor_position()
381+
local winnr = view.get_winnr()
382+
if not winnr or not vim.api.nvim_win_is_valid(winnr) then
383+
return
384+
end
385+
386+
return vim.api.nvim_win_get_cursor(winnr)
387+
end
388+
389+
377390
function Explorer:setup(opts)
378391
config = opts
379392
require("nvim-tree.explorer.watch").setup(opts)

lua/nvim-tree/lib.lua

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,14 @@ local M = {
1313
target_winid = nil,
1414
}
1515

16-
---Cursor position as per vim.api.nvim_win_get_cursor
17-
---nil on no explorer or invalid view win
18-
---@return integer[]|nil
19-
function M.get_cursor_position()
20-
if not core.get_explorer() then
21-
return
22-
end
23-
24-
local winnr = view.get_winnr()
25-
if not winnr or not vim.api.nvim_win_is_valid(winnr) then
26-
return
27-
end
28-
29-
return vim.api.nvim_win_get_cursor(winnr)
30-
end
31-
3216
---@return Node|nil
3317
function M.get_node_at_cursor()
3418
local explorer = core.get_explorer()
3519
if not explorer then
3620
return
3721
end
3822

39-
local cursor = M.get_cursor_position()
23+
local cursor = explorer:get_cursor_position()
4024
if not cursor then
4125
return
4226
end

0 commit comments

Comments
 (0)