Skip to content

Commit 0417d91

Browse files
committed
feat: focus_empty_on_setup
1 parent 540055b commit 0417d91

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

doc/nvim-tree-lua.txt

+7
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ Subsequent calls to setup will replace the previous configuration.
175175
open_on_setup = false,
176176
open_on_setup_file = false,
177177
open_on_tab = false,
178+
focus_empty_on_setup = false,
178179
ignore_buf_on_tab_change = {},
179180
sort_by = "name",
180181
root_dirs = {},
@@ -391,6 +392,7 @@ Hijack netrw windows (overridden if |disable_netrw| is `true`)
391392
*nvim-tree.open_on_setup*
392393
Will automatically open the tree when running setup if startup buffer is
393394
a directory, is empty or is unnamed. nvim-tree window will be focused.
395+
See |nvim-tree.focus_empty_on_setup|
394396
Type: `boolean`, Default: `false`
395397

396398
*nvim-tree.open_on_setup_file*
@@ -427,6 +429,11 @@ Opens the tree automatically when switching tabpage or opening a new tabpage
427429
if the tree was previously open.
428430
Type: `boolean`, Default: `false`
429431

432+
*nvim-tree.focus_empty_on_setup*
433+
When the tree opens as a result of |nvim-tree.open_on_setup| or
434+
|nvim-tree.open_on_tab| and the buffer is empty, focus the buffer.
435+
Type: `boolean`, Default: `false`
436+
430437
*nvim-tree.sort_by*
431438
Changes how files within the same directory are sorted.
432439
Can be one of `name`, `case_sensitive`, `modification_time`, `extension` or a

lua/nvim-tree.lua

+6-1
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,10 @@ function M.on_enter(netrw_disabled)
244244
local should_focus_other_window = false
245245
local should_find = false
246246
if (_config.open_on_setup or _config.open_on_setup_file) and not should_be_preserved then
247-
if buf_is_dir or buf_is_empty then
247+
if buf_is_empty then
248+
should_open = true
249+
should_focus_other_window = _config.focus_empty_on_setup
250+
elseif buf_is_dir then
248251
should_open = true
249252
elseif is_file and _config.open_on_setup_file then
250253
should_open = true
@@ -431,6 +434,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
431434
open_on_setup = false,
432435
open_on_setup_file = false,
433436
open_on_tab = false,
437+
focus_empty_on_setup = false,
434438
ignore_buf_on_tab_change = {},
435439
sort_by = "name",
436440
root_dirs = {},
@@ -704,6 +708,7 @@ function M.setup(conf)
704708
_config.update_focused_file = opts.update_focused_file
705709
_config.open_on_setup = opts.open_on_setup
706710
_config.open_on_setup_file = opts.open_on_setup_file
711+
_config.focus_empty_on_setup = opts.focus_empty_on_setup
707712
_config.ignore_buffer_on_setup = opts.ignore_buffer_on_setup
708713
_config.ignore_ft_on_setup = opts.ignore_ft_on_setup
709714
_config.ignore_buf_on_tab_change = opts.ignore_buf_on_tab_change

0 commit comments

Comments
 (0)