Skip to content

Commit be2b4f5

Browse files
authored
fix(#1615): focus created file when command line prompt requires confirmation (#1622)
* fix(#1615): focus created file when command line prompt requires confirmation * fix(#1615): focus created file when command line prompt requires confirmation
1 parent c5536db commit be2b4f5

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

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

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ local utils = require "nvim-tree.utils"
44
local events = require "nvim-tree.events"
55
local lib = require "nvim-tree.lib"
66
local core = require "nvim-tree.core"
7+
local watch = require "nvim-tree.explorer.watch"
78

89
local M = {}
910

@@ -107,11 +108,11 @@ function M.fn(node)
107108
events._dispatch_folder_created(new_file_path)
108109
if M.enable_reload then
109110
require("nvim-tree.actions.reloaders.reloaders").reload_explorer()
111+
else
112+
-- synchronous call required so that we may focus the file now
113+
watch.refresh_path(node.absolute_path)
110114
end
111-
-- INFO: defer needed when reload is automatic (watchers)
112-
vim.defer_fn(function()
113-
utils.focus_file(utils.path_remove_trailing(new_file_path))
114-
end, 150)
115+
utils.focus_file(utils.path_remove_trailing(new_file_path))
115116
end)
116117
end
117118

lua/nvim-tree/explorer/watch.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ local function is_folder_ignored(path)
3939
return false
4040
end
4141

42-
local function refresh_path(path)
42+
function M.refresh_path(path)
4343
log.line("watcher", "node event executing '%s'", path)
4444
local n = utils.get_node_from_path(path)
4545
if not n then
@@ -65,7 +65,7 @@ function M.create_watcher(absolute_path)
6565
local function callback(watcher)
6666
log.line("watcher", "node event scheduled %s", watcher.context)
6767
utils.debounce(watcher.context, M.debounce_delay, function()
68-
refresh_path(watcher._path)
68+
M.refresh_path(watcher._path)
6969
end)
7070
end
7171

0 commit comments

Comments
 (0)