Skip to content

Commit 7e89276

Browse files
committed
Revert "fix(#1716): focus file/directory when created in a sub-directory, don't dispatch FolderCreated on file creation (#1722)"
This reverts commit bdc4ec6.
1 parent d91f885 commit 7e89276

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ local utils = require "nvim-tree.utils"
22
local events = require "nvim-tree.events"
33
local lib = require "nvim-tree.lib"
44
local core = require "nvim-tree.core"
5+
local watch = require "nvim-tree.explorer.watch"
56
local notify = require "nvim-tree.notify"
67

78
local M = {}
@@ -98,15 +99,22 @@ function M.fn(node)
9899
is_error = true
99100
break
100101
end
101-
events._dispatch_folder_created(path_to_create)
102102
end
103103
end
104104
if not is_error then
105105
notify.info(new_file_path .. " was properly created")
106106
end
107-
108-
-- implicitly refreshes contents
109-
require("nvim-tree.actions.finders.find-file").fn(new_file_path)
107+
events._dispatch_folder_created(new_file_path)
108+
if M.enable_reload then
109+
require("nvim-tree.actions.reloaders.reloaders").reload_explorer()
110+
else
111+
-- synchronous call required so that we may focus the file now
112+
node = node.nodes ~= nil and node or node.parent
113+
if node then
114+
watch.refresh_path(node.absolute_path)
115+
end
116+
end
117+
utils.focus_file(utils.path_remove_trailing(new_file_path))
110118
end)
111119
end
112120

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ 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"
76

87
local M = {}
98

@@ -40,16 +39,11 @@ function M.reload_explorer()
4039
end
4140
event_running = true
4241

43-
local ps = log.profile_start "reload_explorer"
44-
4542
local projects = git.reload()
4643
refresh_nodes(core.get_explorer(), projects)
4744
if view.is_visible() then
4845
renderer.draw()
4946
end
50-
51-
log.profile_end(ps, "reload_explorer")
52-
5347
event_running = false
5448
end
5549

@@ -59,14 +53,9 @@ function M.reload_git()
5953
end
6054
event_running = true
6155

62-
local ps = log.profile_start "reload_git"
63-
6456
local projects = git.reload()
6557
M.reload_node_status(core.get_explorer(), projects)
6658
renderer.draw()
67-
68-
log.profile_end(ps, "reload_git")
69-
7059
event_running = false
7160
end
7261

0 commit comments

Comments
 (0)