Skip to content

Commit 40dd577

Browse files
authored
fix(setup): explicitly specify path to hijack when possible (#1718)
1 parent 2a5c86b commit 40dd577

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

Diff for: lua/neo-tree.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ local function try_netrw_hijack(path)
9494
local netrw = require("neo-tree.setup.netrw")
9595
if netrw.get_hijack_behavior() ~= "disabled" then
9696
vim.cmd("silent! autocmd! FileExplorer *")
97-
return netrw.hijack()
97+
return netrw.hijack(path)
9898
end
9999
return false
100100
end

Diff for: lua/neo-tree/setup/netrw.lua

+5-4
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,16 @@ M.get_hijack_behavior = function()
2323
end
2424
end
2525

26+
---@param path string? Path to hijack (sometimes bufname doesn't set in time)
2627
---@return boolean hijacked Whether the hijack was successful
27-
M.hijack = function()
28-
local manager = require("neo-tree.sources.manager")
29-
local log = require("neo-tree.log")
28+
M.hijack = function(path)
3029
local hijack_behavior = M.get_hijack_behavior()
3130
if hijack_behavior == "disabled" then
3231
return false
3332
end
3433

3534
-- ensure this is a directory
36-
local bufname = vim.api.nvim_buf_get_name(0)
35+
local bufname = path or vim.api.nvim_buf_get_name(0)
3736
local stats = vim.loop.fs_stat(bufname)
3837
if not stats then
3938
return false
@@ -48,6 +47,8 @@ M.hijack = function()
4847
local winid = vim.api.nvim_get_current_win()
4948
local dir_bufnr = vim.api.nvim_get_current_buf()
5049

50+
local manager = require("neo-tree.sources.manager")
51+
local log = require("neo-tree.log")
5152
-- Now actually open the tree, with a very quick debounce because this may be
5253
-- called multiple times in quick succession.
5354
utils.debounce("hijack_netrw_" .. winid, function()

Diff for: plugin/neo-tree.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ local function try_netrw_hijack(path)
2525
local netrw = require("neo-tree.setup.netrw")
2626
if netrw.get_hijack_behavior() ~= "disabled" then
2727
vim.cmd("silent! autocmd! FileExplorer *")
28-
return netrw.hijack()
28+
return netrw.hijack(path)
2929
end
3030
return false
3131
end

0 commit comments

Comments
 (0)