Skip to content

Commit c5536db

Browse files
authored
fix(#1270): open_on_setup_file does not override open_on_setup, hijack_directories does not override startup behaviour (#1618)
1 parent 7282f7d commit c5536db

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

doc/nvim-tree-lua.txt

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -390,29 +390,33 @@ Hijack netrw windows (overridden if |disable_netrw| is `true`)
390390
Type: `boolean`, Default: `true`
391391

392392
*nvim-tree.open_on_setup*
393-
Will automatically open the tree when running setup if startup buffer is
394-
a directory, is empty or is unnamed. nvim-tree window will be focused.
393+
Will automatically open the tree when running setup if startup buffer is a
394+
directory, empty or unnamed.
395+
nvim-tree window will be focused.
395396
See |nvim-tree.focus_empty_on_setup|
396397
Type: `boolean`, Default: `false`
397398

398399
*nvim-tree.open_on_setup_file*
399-
Will automatically open the tree when running setup if startup buffer is a file.
400+
Will automatically open the tree when running setup if startup buffer is a
401+
file.
400402
File window will be focused.
401-
File will be found if update_focused_file is enabled.
403+
File will be found if |nvim-tree.update_focused_file| is enabled.
402404
Type: `boolean`, Default: `false`
403405

404406
*nvim-tree.ignore_buffer_on_setup*
405-
Will ignore the buffer, when deciding to open the tree on setup.
407+
Always open the tree when |nvim-tree.open_on_setup| is enabled, regardless of
408+
the startup buffer.
409+
Buffer window will be focused.
406410
Type: `boolean`, Default: `false`
407411

408412
*nvim-tree.ignore_ft_on_setup*
409-
List of filetypes that will prevent `open_on_setup` to open.
413+
List of filetypes that will prevent |nvim-tree.open_on_setup_file|.
410414
You can use this option if you don't want the tree to open
411415
in some scenarios (eg using vim startify).
412416
Type: {string}, Default: `{}`
413417

414418
*nvim-tree.ignore_buf_on_tab_change*
415-
List of filetypes or buffer names that will prevent `open_on_tab` to open.
419+
List of filetypes or buffer names that will prevent |nvim-tree.open_on_tab|.
416420
Type: {string}, Default: `{}`
417421

418422
*nvim-tree.auto_reload_on_write*

lua/nvim-tree.lua

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -237,40 +237,34 @@ function M.on_enter(netrw_disabled)
237237
local buf_has_content = #lines > 1 or (#lines == 1 and lines[1] ~= "")
238238

239239
local buf_is_dir = is_dir and netrw_disabled
240-
local buf_is_empty = bufname == "" and not buf_has_content
241240
local should_be_preserved = vim.tbl_contains(ft_ignore, buftype)
242241

243242
local should_open = false
244243
local should_focus_other_window = false
245244
local should_find = false
246245
if (_config.open_on_setup or _config.open_on_setup_file) and not should_be_preserved then
247-
if buf_is_empty then
246+
if not buf_has_content and _config.open_on_setup then
248247
should_open = true
249248
should_focus_other_window = _config.focus_empty_on_setup
250-
elseif buf_is_dir then
249+
elseif buf_is_dir and _config.open_on_setup then
251250
should_open = true
252251
elseif is_file and _config.open_on_setup_file then
253252
should_open = true
254253
should_focus_other_window = true
255254
should_find = _config.update_focused_file.enable
256-
elseif _config.ignore_buffer_on_setup then
255+
elseif _config.ignore_buffer_on_setup and _config.open_on_setup then
257256
should_open = true
258257
should_focus_other_window = true
259258
end
260259
end
261260

262-
local should_hijack = _config.hijack_directories.enable
263-
and _config.hijack_directories.auto_open
264-
and is_dir
265-
and not should_be_preserved
266-
267261
-- Session that left a NvimTree Buffer opened, reopen with it
268262
local existing_tree_wins = find_existing_windows()
269263
if existing_tree_wins[1] then
270264
api.nvim_set_current_win(existing_tree_wins[1])
271265
end
272266

273-
if should_open or should_hijack or existing_tree_wins[1] ~= nil then
267+
if should_open or existing_tree_wins[1] ~= nil then
274268
lib.open(cwd)
275269

276270
if should_focus_other_window then

0 commit comments

Comments
 (0)