From 6a51945a2381fb948b3999ccb0ea7f2d8e54beb4 Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Tue, 4 Oct 2022 12:40:51 +1100 Subject: [PATCH 1/2] fix(#1615): focus created file when command line prompt requires confirmation --- lua/nvim-tree/actions/fs/create-file.lua | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lua/nvim-tree/actions/fs/create-file.lua b/lua/nvim-tree/actions/fs/create-file.lua index 552d1838a19..14a53bd653a 100644 --- a/lua/nvim-tree/actions/fs/create-file.lua +++ b/lua/nvim-tree/actions/fs/create-file.lua @@ -107,11 +107,10 @@ 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 + require("nvim-tree.explorer.reload").reload(node, {}) 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 From 1cf428ae676fd0f37ed3acff6f36a934521493ca Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Tue, 4 Oct 2022 12:58:10 +1100 Subject: [PATCH 2/2] fix(#1615): focus created file when command line prompt requires confirmation --- lua/nvim-tree/actions/fs/create-file.lua | 4 +++- lua/nvim-tree/explorer/watch.lua | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lua/nvim-tree/actions/fs/create-file.lua b/lua/nvim-tree/actions/fs/create-file.lua index 14a53bd653a..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 = {} @@ -108,7 +109,8 @@ function M.fn(node) if M.enable_reload then require("nvim-tree.actions.reloaders.reloaders").reload_explorer() else - require("nvim-tree.explorer.reload").reload(node, {}) + -- synchronous call required so that we may focus the file now + watch.refresh_path(node.absolute_path) end utils.focus_file(utils.path_remove_trailing(new_file_path)) 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