diff --git a/lua/nvim-tree/actions/fs/create-file.lua b/lua/nvim-tree/actions/fs/create-file.lua index 552d1838a19..d93b9ecee31 100644 --- a/lua/nvim-tree/actions/fs/create-file.lua +++ b/lua/nvim-tree/actions/fs/create-file.lua @@ -4,6 +4,7 @@ local utils = require "nvim-tree.utils" local events = require "nvim-tree.events" local lib = require "nvim-tree.lib" local core = require "nvim-tree.core" +local watch = require "nvim-tree.explorer.watch" local M = {} @@ -107,11 +108,11 @@ function M.fn(node) events._dispatch_folder_created(new_file_path) if M.enable_reload then require("nvim-tree.actions.reloaders.reloaders").reload_explorer() + else + -- synchronous call required so that we may focus the file now + watch.refresh_path(node.absolute_path) end - -- INFO: defer needed when reload is automatic (watchers) - vim.defer_fn(function() - utils.focus_file(utils.path_remove_trailing(new_file_path)) - end, 150) + utils.focus_file(utils.path_remove_trailing(new_file_path)) end) end diff --git a/lua/nvim-tree/explorer/watch.lua b/lua/nvim-tree/explorer/watch.lua index 785a6e0c621..342b4c1f28b 100644 --- a/lua/nvim-tree/explorer/watch.lua +++ b/lua/nvim-tree/explorer/watch.lua @@ -39,7 +39,7 @@ local function is_folder_ignored(path) return false end -local function refresh_path(path) +function M.refresh_path(path) log.line("watcher", "node event executing '%s'", path) local n = utils.get_node_from_path(path) if not n then @@ -65,7 +65,7 @@ function M.create_watcher(absolute_path) local function callback(watcher) log.line("watcher", "node event scheduled %s", watcher.context) utils.debounce(watcher.context, M.debounce_delay, function() - refresh_path(watcher._path) + M.refresh_path(watcher._path) end) end