Skip to content

Commit 940063e

Browse files
authored
fix(setup): disable lazyloading autocmd when already setup (#1721)
1 parent 71f3b8e commit 940063e

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

lua/neo-tree.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ end
8080

8181
---Ideally this should only be in plugin/neo-tree.lua but lazy-loading might mean this runs before bufenter
8282
---@param path string? The path to check
83-
---@return boolean hijacked Whether the hijack worked
83+
---@return boolean hijacked Whether we hijacked a buffer
8484
local function try_netrw_hijack(path)
8585
if not path or #path == 0 then
8686
return false

lua/neo-tree/setup/init.lua

+1
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,7 @@ M.merge_config = function(user_config)
496496
define_events()
497497

498498
-- Prevent accidentally opening another file in the neo-tree window.
499+
vim.g.neotree_watching_bufenter = 1
499500
events.subscribe({
500501
event = events.VIM_BUFFER_ENTER,
501502
handler = M.buffer_enter_event,

lua/neo-tree/setup/netrw.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ M.hijack = function(path)
5050
local winid = vim.api.nvim_get_current_win()
5151
local dir_bufnr = vim.api.nvim_get_current_buf()
5252

53-
local manager = require("neo-tree.sources.manager")
54-
local log = require("neo-tree.log")
5553
-- Now actually open the tree, with a very quick debounce because this may be
5654
-- called multiple times in quick succession.
5755
utils.debounce("hijack_netrw_" .. winid, function()
56+
local manager = require("neo-tree.sources.manager")
57+
local log = require("neo-tree.log")
5858
-- We will want to replace the "directory" buffer with either the "alternate"
5959
-- buffer or a new blank one.
6060
local replace_with_bufnr = vim.fn.bufnr("#")

plugin/neo-tree.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ end, {
1111
})
1212

1313
---@param path string? The path to check
14-
---@return boolean hijacked Whether the hijack worked
14+
---@return boolean hijacked Whether we hijacked a buffer
1515
local function try_netrw_hijack(path)
1616
if not path or #path == 0 then
1717
return false
@@ -35,7 +35,7 @@ local augroup = vim.api.nvim_create_augroup("NeoTree_NetrwDeferred", { clear = t
3535
vim.api.nvim_create_autocmd("BufEnter", {
3636
group = augroup,
3737
callback = function(args)
38-
if try_netrw_hijack(args.file) then
38+
if vim.g.neotree_watching_bufenter == 1 or try_netrw_hijack(args.file) then
3939
vim.api.nvim_del_augroup_by_id(augroup)
4040
end
4141
end,

0 commit comments

Comments
 (0)