Skip to content

fix(#1664): respect hijack_directories.enable on startup when not open_on_setup #1665

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
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
3 changes: 2 additions & 1 deletion doc/nvim-tree-lua.txt
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,8 @@ Will change cwd of nvim-tree to that of new buffer's when opening nvim-tree.
Type: `boolean`, Default: `false`

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

*nvim-tree.hijack_directories.enable*
Enable the feature.
Expand Down
7 changes: 6 additions & 1 deletion lua/nvim-tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -257,13 +257,18 @@ function M.on_enter(netrw_disabled)
end
end

local should_hijack = _config.hijack_directories.enable
and _config.hijack_directories.auto_open
and is_dir
and not should_be_preserved

-- Session that left a NvimTree Buffer opened, reopen with it
local existing_tree_wins = find_existing_windows()
if existing_tree_wins[1] then
api.nvim_set_current_win(existing_tree_wins[1])
end

if should_open or existing_tree_wins[1] ~= nil then
if should_open or should_hijack or existing_tree_wins[1] ~= nil then
lib.open(cwd)

if should_focus_other_window then
Expand Down