move lib.get_cursor_position to Explorer
This commit is contained in:
@@ -34,11 +34,16 @@ end
|
|||||||
---@param what string type of status
|
---@param what string type of status
|
||||||
---@param skip_gitignored boolean default false
|
---@param skip_gitignored boolean default false
|
||||||
local function move(where, what, skip_gitignored)
|
local function move(where, what, skip_gitignored)
|
||||||
|
local explorer = core.get_explorer()
|
||||||
|
if not explorer then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local first_node_line = core.get_nodes_starting_line()
|
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 nodes_by_line = utils.get_nodes_by_line(explorer.nodes, first_node_line)
|
||||||
local iter_start, iter_end, iter_step, cur, first, nex
|
local iter_start, iter_end, iter_step, cur, first, nex
|
||||||
|
|
||||||
local cursor = lib.get_cursor_position()
|
local cursor = explorer:get_cursor_position()
|
||||||
if cursor and cursor[1] < first_node_line then
|
if cursor and cursor[1] < first_node_line then
|
||||||
cur = cursor[1]
|
cur = cursor[1]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -374,6 +374,19 @@ function Explorer:reload_git()
|
|||||||
event_running = false
|
event_running = false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---Cursor position as per vim.api.nvim_win_get_cursor
|
||||||
|
---nil on no explorer or invalid view win
|
||||||
|
---@return integer[]|nil
|
||||||
|
function Explorer:get_cursor_position()
|
||||||
|
local winnr = view.get_winnr()
|
||||||
|
if not winnr or not vim.api.nvim_win_is_valid(winnr) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
return vim.api.nvim_win_get_cursor(winnr)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function Explorer:setup(opts)
|
function Explorer:setup(opts)
|
||||||
config = opts
|
config = opts
|
||||||
require("nvim-tree.explorer.watch").setup(opts)
|
require("nvim-tree.explorer.watch").setup(opts)
|
||||||
|
|||||||
@@ -13,22 +13,6 @@ local M = {
|
|||||||
target_winid = nil,
|
target_winid = nil,
|
||||||
}
|
}
|
||||||
|
|
||||||
---Cursor position as per vim.api.nvim_win_get_cursor
|
|
||||||
---nil on no explorer or invalid view win
|
|
||||||
---@return integer[]|nil
|
|
||||||
function M.get_cursor_position()
|
|
||||||
if not core.get_explorer() then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local winnr = view.get_winnr()
|
|
||||||
if not winnr or not vim.api.nvim_win_is_valid(winnr) then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
return vim.api.nvim_win_get_cursor(winnr)
|
|
||||||
end
|
|
||||||
|
|
||||||
---@return Node|nil
|
---@return Node|nil
|
||||||
function M.get_node_at_cursor()
|
function M.get_node_at_cursor()
|
||||||
local explorer = core.get_explorer()
|
local explorer = core.get_explorer()
|
||||||
@@ -36,7 +20,7 @@ function M.get_node_at_cursor()
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local cursor = M.get_cursor_position()
|
local cursor = explorer:get_cursor_position()
|
||||||
if not cursor then
|
if not cursor then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user