Skip to content

fix(#1716): focus file/directory when created in a sub-directory, don't dispatch FolderCreated on file creation #1722

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions lua/nvim-tree/actions/fs/create-file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ 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 notify = require "nvim-tree.notify"

local M = {}
Expand Down Expand Up @@ -101,22 +100,15 @@ function M.fn(node)
is_error = true
break
end
events._dispatch_folder_created(path_to_create)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated bug

end
end
if not is_error then
notify.info(new_file_path .. " was properly created")
end
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
node = node.nodes ~= nil and node or node.parent
if node then
watch.refresh_path(node.absolute_path)
end
end
utils.focus_file(utils.path_remove_trailing(new_file_path))

-- implicitly refreshes contents
require("nvim-tree.actions.finders.find-file").fn(new_file_path)
end)
end

Expand Down
11 changes: 11 additions & 0 deletions lua/nvim-tree/actions/reloaders/reloaders.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local view = require "nvim-tree.view"
local renderer = require "nvim-tree.renderer"
local explorer_module = require "nvim-tree.explorer"
local core = require "nvim-tree.core"
local log = require "nvim-tree.log"

local M = {}

Expand Down Expand Up @@ -39,11 +40,16 @@ function M.reload_explorer()
end
event_running = true

local ps = log.profile_start "reload_explorer"

local projects = git.reload()
refresh_nodes(core.get_explorer(), projects)
if view.is_visible() then
renderer.draw()
end

log.profile_end(ps, "reload_explorer")

event_running = false
end

Expand All @@ -53,9 +59,14 @@ function M.reload_git()
end
event_running = true

local ps = log.profile_start "reload_git"

local projects = git.reload()
M.reload_node_status(core.get_explorer(), projects)
renderer.draw()

log.profile_end(ps, "reload_git")

event_running = false
end

Expand Down