refactor(#2826): multi instance nvim-tree.view

This commit is contained in:
Mateusz Russak
2024-08-04 13:31:11 +02:00
parent 0f2cda6ce0
commit fa051cf990
22 changed files with 390 additions and 297 deletions

View File

@@ -1,5 +1,4 @@
local utils = require "nvim-tree.utils"
local view = require "nvim-tree.view"
local core = require "nvim-tree.core"
local lib = require "nvim-tree.lib"
local explorer_node = require "nvim-tree.explorer.node"
@@ -60,10 +59,14 @@ local function move(where, what, skip_gitignored)
end
end
local explorer = core.get_explorer()
if not explorer then
return
end
if nex then
view.set_cursor { nex, 0 }
explorer.view:set_cursor { nex, 0 }
elseif vim.o.wrapscan and first then
view.set_cursor { first, 0 }
explorer.view:set_cursor { first, 0 }
end
end
@@ -182,13 +185,19 @@ local function move_prev_recursive(what, skip_gitignored)
-- 4.3)
if node_init.name == ".." then -- root node
view.set_cursor { 1, 0 } -- move to root node (position 1)
local explorer = core.get_explorer()
if explorer then
explorer.view:set_cursor { 1, 0 } -- move to root node (position 1)
end
else
local node_init_line = utils.find_node_line(node_init)
if node_init_line < 0 then
return
end
view.set_cursor { node_init_line, 0 }
local explorer = core.get_explorer()
if explorer then
explorer.view:set_cursor { node_init_line, 0 } -- move to root node (position 1)
end
end
-- 4.4)

View File

@@ -1,5 +1,4 @@
local renderer = require "nvim-tree.renderer"
local view = require "nvim-tree.view"
local utils = require "nvim-tree.utils"
local core = require "nvim-tree.core"
local lib = require "nvim-tree.lib"
@@ -21,14 +20,20 @@ function M.fn(should_close)
local parent = utils.get_parent_of_group(node).parent
if not parent or not parent.parent then
return view.set_cursor { 1, 0 }
local explorer = core.get_explorer()
if explorer then
return explorer.view:set_cursor { 1, 0 }
end
end
local _, line = utils.find_node(core.get_explorer().nodes, function(n)
return n.absolute_path == parent.absolute_path
end)
view.set_cursor { line + 1, 0 }
local explorer = core.get_explorer()
if explorer then
explorer.view:set_cursor { line + 1, 0 }
end
if should_close then
parent.open = false
renderer.draw()