Skip to content

Commit bdc4ec6

Browse files
authored
fix(#1716): focus file/directory when created in a sub-directory, don't dispatch FolderCreated on file creation (#1722)
* fix(#1716): focus file/directory when created in a sub-directory, don't dispatch FolderCreated on file creation * fix(#1716): focus file/directory when created in a sub-directory * fix(#1716): focus file/directory when created in a sub-directory
1 parent be2ccd4 commit bdc4ec6

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

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

+4-12
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ 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"
87
local notify = require "nvim-tree.notify"
98

109
local M = {}
@@ -101,22 +100,15 @@ function M.fn(node)
101100
is_error = true
102101
break
103102
end
103+
events._dispatch_folder_created(path_to_create)
104104
end
105105
end
106106
if not is_error then
107107
notify.info(new_file_path .. " was properly created")
108108
end
109-
events._dispatch_folder_created(new_file_path)
110-
if M.enable_reload then
111-
require("nvim-tree.actions.reloaders.reloaders").reload_explorer()
112-
else
113-
-- synchronous call required so that we may focus the file now
114-
node = node.nodes ~= nil and node or node.parent
115-
if node then
116-
watch.refresh_path(node.absolute_path)
117-
end
118-
end
119-
utils.focus_file(utils.path_remove_trailing(new_file_path))
109+
110+
-- implicitly refreshes contents
111+
require("nvim-tree.actions.finders.find-file").fn(new_file_path)
120112
end)
121113
end
122114

lua/nvim-tree/actions/reloaders/reloaders.lua

+11
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ local view = require "nvim-tree.view"
33
local renderer = require "nvim-tree.renderer"
44
local explorer_module = require "nvim-tree.explorer"
55
local core = require "nvim-tree.core"
6+
local log = require "nvim-tree.log"
67

78
local M = {}
89

@@ -39,11 +40,16 @@ function M.reload_explorer()
3940
end
4041
event_running = true
4142

43+
local ps = log.profile_start "reload_explorer"
44+
4245
local projects = git.reload()
4346
refresh_nodes(core.get_explorer(), projects)
4447
if view.is_visible() then
4548
renderer.draw()
4649
end
50+
51+
log.profile_end(ps, "reload_explorer")
52+
4753
event_running = false
4854
end
4955

@@ -53,9 +59,14 @@ function M.reload_git()
5359
end
5460
event_running = true
5561

62+
local ps = log.profile_start "reload_git"
63+
5664
local projects = git.reload()
5765
M.reload_node_status(core.get_explorer(), projects)
5866
renderer.draw()
67+
68+
log.profile_end(ps, "reload_git")
69+
5970
event_running = false
6071
end
6172

0 commit comments

Comments
 (0)