Skip to content

Commit 4e24505

Browse files
authored
fix(#1664): respect hijack_directories.enable on startup when not open_on_setup (#1665)
1 parent 48992fd commit 4e24505

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

doc/nvim-tree-lua.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,8 @@ Will change cwd of nvim-tree to that of new buffer's when opening nvim-tree.
491491
Type: `boolean`, Default: `false`
492492

493493
*nvim-tree.hijack_directories* (previously `update_to_buf_dir`)
494-
hijacks new directory buffers when they are opened (`:e dir`).
494+
hijacks new directory buffers when they are opened (`:e dir`) or if a
495+
directory is opened on startup e.g. `nvim .`
495496

496497
*nvim-tree.hijack_directories.enable*
497498
Enable the feature.

lua/nvim-tree.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,13 +257,18 @@ function M.on_enter(netrw_disabled)
257257
end
258258
end
259259

260+
local should_hijack = _config.hijack_directories.enable
261+
and _config.hijack_directories.auto_open
262+
and is_dir
263+
and not should_be_preserved
264+
260265
-- Session that left a NvimTree Buffer opened, reopen with it
261266
local existing_tree_wins = find_existing_windows()
262267
if existing_tree_wins[1] then
263268
api.nvim_set_current_win(existing_tree_wins[1])
264269
end
265270

266-
if should_open or existing_tree_wins[1] ~= nil then
271+
if should_open or should_hijack or existing_tree_wins[1] ~= nil then
267272
lib.open(cwd)
268273

269274
if should_focus_other_window then

0 commit comments

Comments
 (0)