refactor(#2942): multi instance: move focus_file to Explorer
This commit is contained in:
parent
29d8c83ba8
commit
a20c81733a
@ -1,4 +1,3 @@
|
||||
local utils = require("nvim-tree.utils")
|
||||
local core = require("nvim-tree.core")
|
||||
local Iterator = require("nvim-tree.iterators.node-iterator")
|
||||
|
||||
@ -12,9 +11,14 @@ function M.fn(direction)
|
||||
return
|
||||
end
|
||||
|
||||
local explorer = core.get_explorer()
|
||||
if not explorer then
|
||||
return
|
||||
end
|
||||
|
||||
local first, last, next, prev = nil, nil, nil, nil
|
||||
local found = false
|
||||
local parent = node.parent or core.get_explorer()
|
||||
local parent = node.parent or explorer
|
||||
Iterator.builder(parent and parent.nodes or {})
|
||||
:recursor(function()
|
||||
return nil
|
||||
@ -45,7 +49,7 @@ function M.fn(direction)
|
||||
end
|
||||
|
||||
if target_node then
|
||||
utils.focus_file(target_node.absolute_path)
|
||||
explorer:focus_file(target_node.absolute_path)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -599,6 +599,14 @@ function Explorer:get_node_from_path(path)
|
||||
:iterate()
|
||||
end
|
||||
|
||||
---@param path string
|
||||
function Explorer:focus_file(path)
|
||||
local _, i = utils.find_node(self.nodes, function(node)
|
||||
return node.absolute_path == path
|
||||
end)
|
||||
view.set_cursor({ i + 1, 1 })
|
||||
end
|
||||
|
||||
---Api.tree.get_nodes
|
||||
---@return nvim_tree.api.Node
|
||||
function Explorer:get_nodes()
|
||||
|
||||
@ -220,9 +220,9 @@ function LiveFilter:clear_filter()
|
||||
self.explorer.renderer:draw()
|
||||
|
||||
if node then
|
||||
utils.focus_file(node.absolute_path)
|
||||
self.explorer:focus_file(node.absolute_path)
|
||||
elseif last_node then
|
||||
utils.focus_file(last_node.absolute_path)
|
||||
self.explorer:focus_file(last_node.absolute_path)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -263,7 +263,7 @@ function Marks:navigate_select()
|
||||
if node and not node:is(DirectoryNode) and not utils.get_win_buf_from_path(node.absolute_path) then
|
||||
open_file.fn("edit", node.absolute_path)
|
||||
elseif node then
|
||||
utils.focus_file(node.absolute_path)
|
||||
self.explorer:focus_file(node.absolute_path)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
@ -447,13 +447,6 @@ function M.debounce(context, timeout, callback)
|
||||
end)
|
||||
end
|
||||
|
||||
function M.focus_file(path)
|
||||
local _, i = M.find_node(require("nvim-tree.core").get_explorer().nodes, function(node)
|
||||
return node.absolute_path == path
|
||||
end)
|
||||
require("nvim-tree.view").set_cursor({ i + 1, 1 })
|
||||
end
|
||||
|
||||
---Focus node passed as parameter if visible, otherwise focus first visible parent.
|
||||
---If none of the parents is visible focus root.
|
||||
---If node is nil do nothing.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user