Skip to content

Commit a20c817

Browse files
committed
refactor(#2942): multi instance: move focus_file to Explorer
1 parent 29d8c83 commit a20c817

File tree

5 files changed

+18
-13
lines changed

5 files changed

+18
-13
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
local utils = require("nvim-tree.utils")
21
local core = require("nvim-tree.core")
32
local Iterator = require("nvim-tree.iterators.node-iterator")
43

@@ -12,9 +11,14 @@ function M.fn(direction)
1211
return
1312
end
1413

14+
local explorer = core.get_explorer()
15+
if not explorer then
16+
return
17+
end
18+
1519
local first, last, next, prev = nil, nil, nil, nil
1620
local found = false
17-
local parent = node.parent or core.get_explorer()
21+
local parent = node.parent or explorer
1822
Iterator.builder(parent and parent.nodes or {})
1923
:recursor(function()
2024
return nil
@@ -45,7 +49,7 @@ function M.fn(direction)
4549
end
4650

4751
if target_node then
48-
utils.focus_file(target_node.absolute_path)
52+
explorer:focus_file(target_node.absolute_path)
4953
end
5054
end
5155
end

lua/nvim-tree/explorer/init.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,14 @@ function Explorer:get_node_from_path(path)
599599
:iterate()
600600
end
601601

602+
---@param path string
603+
function Explorer:focus_file(path)
604+
local _, i = utils.find_node(self.nodes, function(node)
605+
return node.absolute_path == path
606+
end)
607+
view.set_cursor({ i + 1, 1 })
608+
end
609+
602610
---Api.tree.get_nodes
603611
---@return nvim_tree.api.Node
604612
function Explorer:get_nodes()

lua/nvim-tree/explorer/live-filter.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,9 @@ function LiveFilter:clear_filter()
220220
self.explorer.renderer:draw()
221221

222222
if node then
223-
utils.focus_file(node.absolute_path)
223+
self.explorer:focus_file(node.absolute_path)
224224
elseif last_node then
225-
utils.focus_file(last_node.absolute_path)
225+
self.explorer:focus_file(last_node.absolute_path)
226226
end
227227
end
228228

lua/nvim-tree/marks/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ function Marks:navigate_select()
263263
if node and not node:is(DirectoryNode) and not utils.get_win_buf_from_path(node.absolute_path) then
264264
open_file.fn("edit", node.absolute_path)
265265
elseif node then
266-
utils.focus_file(node.absolute_path)
266+
self.explorer:focus_file(node.absolute_path)
267267
end
268268
end)
269269
end

lua/nvim-tree/utils.lua

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -447,13 +447,6 @@ function M.debounce(context, timeout, callback)
447447
end)
448448
end
449449

450-
function M.focus_file(path)
451-
local _, i = M.find_node(require("nvim-tree.core").get_explorer().nodes, function(node)
452-
return node.absolute_path == path
453-
end)
454-
require("nvim-tree.view").set_cursor({ i + 1, 1 })
455-
end
456-
457450
---Focus node passed as parameter if visible, otherwise focus first visible parent.
458451
---If none of the parents is visible focus root.
459452
---If node is nil do nothing.

0 commit comments

Comments
 (0)