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

This commit is contained in:
Alexander Courtis 2022-10-17 14:49:57 +11:00 committed by GitHub
parent 48992fd3e8
commit 4e24505e2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View File

@ -491,7 +491,8 @@ Will change cwd of nvim-tree to that of new buffer's when opening nvim-tree.
Type: `boolean`, Default: `false` Type: `boolean`, Default: `false`
*nvim-tree.hijack_directories* (previously `update_to_buf_dir`) *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* *nvim-tree.hijack_directories.enable*
Enable the feature. Enable the feature.

View File

@ -257,13 +257,18 @@ function M.on_enter(netrw_disabled)
end end
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 -- Session that left a NvimTree Buffer opened, reopen with it
local existing_tree_wins = find_existing_windows() local existing_tree_wins = find_existing_windows()
if existing_tree_wins[1] then if existing_tree_wins[1] then
api.nvim_set_current_win(existing_tree_wins[1]) api.nvim_set_current_win(existing_tree_wins[1])
end 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) lib.open(cwd)
if should_focus_other_window then if should_focus_other_window then