Skip to content

Commit 078a9e5

Browse files
committed
chore: move focus_file to utils
1 parent df92f15 commit 078a9e5

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

lua/nvim-tree/actions/fs/create-file.lua

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,6 @@ local core = require "nvim-tree.core"
88

99
local M = {}
1010

11-
local function focus_file(file)
12-
local _, i = utils.find_node(core.get_explorer().nodes, function(node)
13-
return node.absolute_path == file
14-
end)
15-
require("nvim-tree.view").set_cursor { i + 1, 1 }
16-
end
17-
1811
local function create_file(file)
1912
if utils.file_exists(file) then
2013
print(file .. " already exists. Overwrite? y/n")
@@ -112,7 +105,7 @@ function M.fn(node)
112105
end
113106
-- INFO: defer needed when reload is automatic (watchers)
114107
vim.defer_fn(function()
115-
focus_file(new_file_path)
108+
utils.focus_file(new_file_path)
116109
end, 150)
117110
end)
118111
end

lua/nvim-tree/utils.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,4 +328,11 @@ function M.debounce(context, timeout, callback)
328328
)
329329
end
330330

331+
function M.focus_file(path)
332+
local _, i = M.find_node(require("nvim-tree.core").get_explorer().nodes, function(node)
333+
return node.absolute_path == path
334+
end)
335+
require("nvim-tree.view").set_cursor { i + 1, 1 }
336+
end
337+
331338
return M

0 commit comments

Comments
 (0)