refacto: abstract TreeExplorer in core.lua
This commit is contained in:
@@ -2,6 +2,8 @@ local utils = require "nvim-tree.utils"
|
||||
local view = require "nvim-tree.view"
|
||||
local diagnostics = require "nvim-tree.diagnostics"
|
||||
local renderer = require "nvim-tree.renderer"
|
||||
local core = require "nvim-tree.core"
|
||||
|
||||
local lib = function()
|
||||
return require "nvim-tree.lib"
|
||||
end
|
||||
@@ -49,7 +51,7 @@ function M.parent_node(should_close)
|
||||
node.open = false
|
||||
altered_tree = true
|
||||
else
|
||||
local line, parent = iter(TreeExplorer.nodes, true)
|
||||
local line, parent = iter(core.get_explorer().nodes, true)
|
||||
if parent == nil then
|
||||
line = 1
|
||||
elseif should_close then
|
||||
@@ -82,16 +84,16 @@ function M.sibling(direction)
|
||||
local parent, _
|
||||
|
||||
-- Check if current node is already at root nodes
|
||||
for index, _node in ipairs(TreeExplorer.nodes) do
|
||||
for index, _node in ipairs(core.get_explorer().nodes) do
|
||||
if node_path == _node.absolute_path then
|
||||
line = index
|
||||
end
|
||||
end
|
||||
|
||||
if line > 0 then
|
||||
parent = TreeExplorer
|
||||
parent = core.get_explorer()
|
||||
else
|
||||
_, parent = iter(TreeExplorer.nodes, true)
|
||||
_, parent = iter(core.get_explorer().nodes, true)
|
||||
if parent ~= nil and #parent.nodes > 1 then
|
||||
line, _ = get_line_from_node(node)(parent.nodes)
|
||||
end
|
||||
@@ -108,7 +110,7 @@ function M.sibling(direction)
|
||||
end
|
||||
local target_node = parent.nodes[index]
|
||||
|
||||
line, _ = get_line_from_node(target_node)(TreeExplorer.nodes, true)
|
||||
line, _ = get_line_from_node(target_node)(core.get_explorer().nodes, true)
|
||||
if not view.is_root_folder_visible() then
|
||||
line = line - 1
|
||||
end
|
||||
@@ -119,7 +121,7 @@ end
|
||||
function M.find_git_item(where)
|
||||
return function()
|
||||
local node_cur = lib().get_node_at_cursor()
|
||||
local nodes_by_line = lib().get_nodes_by_line(TreeExplorer.nodes, view.View.hide_root_folder and 1 or 2)
|
||||
local nodes_by_line = lib().get_nodes_by_line(core.get_explorer().nodes, view.View.hide_root_folder and 1 or 2)
|
||||
|
||||
local cur, first, prev, nex = nil, nil, nil, nil
|
||||
for line, node in pairs(nodes_by_line) do
|
||||
|
||||
Reference in New Issue
Block a user