add open_on_setup_file option (#1133)
This commit is contained in:
parent
8340753e26
commit
6368880968
@ -125,6 +125,7 @@ require'nvim-tree'.setup { -- BEGIN_DEFAULT_OPTS
|
||||
hijack_unnamed_buffer_when_opening = false,
|
||||
ignore_buffer_on_setup = false,
|
||||
open_on_setup = false,
|
||||
open_on_setup_file = false,
|
||||
open_on_tab = false,
|
||||
sort_by = "name",
|
||||
update_cwd = false,
|
||||
|
||||
@ -92,6 +92,7 @@ function.
|
||||
hijack_unnamed_buffer_when_opening = false,
|
||||
ignore_buffer_on_setup = false,
|
||||
open_on_setup = false,
|
||||
open_on_setup_file = false,
|
||||
open_on_tab = false,
|
||||
sort_by = "name",
|
||||
update_cwd = false,
|
||||
@ -196,8 +197,16 @@ Here is a list of the options available in the setup call:
|
||||
default: `true`
|
||||
|
||||
*nvim-tree.open_on_setup*
|
||||
- |open_on_setup|: will automatically open the tree when running setup if current
|
||||
buffer is a directory, is empty or is unnamed.
|
||||
- |open_on_setup|: will automatically open the tree when running setup if
|
||||
startup buffer is a directory, is empty or is unnamed. nvim-tree window will
|
||||
be focused.
|
||||
type: `boolean`
|
||||
default: `false`
|
||||
|
||||
*nvim-tree.open_on_setup_file*
|
||||
- |open_on_setup_file|: will automatically open the tree when running setup if
|
||||
startup buffer is a file. File window will be focused. File will be found if
|
||||
|update_focused_file.enable| is set.
|
||||
type: `boolean`
|
||||
default: `false`
|
||||
|
||||
|
||||
@ -181,6 +181,7 @@ function M.on_enter(netrw_disabled)
|
||||
|
||||
local stats = luv.fs_stat(bufname)
|
||||
local is_dir = stats and stats.type == "directory"
|
||||
local is_file = stats and stats.type == "file"
|
||||
local cwd
|
||||
if is_dir then
|
||||
cwd = vim.fn.expand(bufname)
|
||||
@ -197,9 +198,14 @@ function M.on_enter(netrw_disabled)
|
||||
|
||||
local should_open = false
|
||||
local should_focus_other_window = false
|
||||
if _config.open_on_setup and not should_be_preserved then
|
||||
local should_find = false
|
||||
if (_config.open_on_setup or _config.open_on_setup_file) and not should_be_preserved then
|
||||
if buf_is_dir or buf_is_empty then
|
||||
should_open = true
|
||||
elseif is_file and _config.open_on_setup_file then
|
||||
should_open = true
|
||||
should_focus_other_window = true
|
||||
should_find = _config.update_focused_file.enable
|
||||
elseif _config.ignore_buffer_on_setup then
|
||||
should_open = true
|
||||
should_focus_other_window = true
|
||||
@ -222,6 +228,9 @@ function M.on_enter(netrw_disabled)
|
||||
|
||||
if should_focus_other_window then
|
||||
vim.cmd "noautocmd wincmd p"
|
||||
if should_find then
|
||||
M.find_file(false)
|
||||
end
|
||||
end
|
||||
end
|
||||
M.initialized = true
|
||||
@ -308,6 +317,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
|
||||
hijack_unnamed_buffer_when_opening = false,
|
||||
ignore_buffer_on_setup = false,
|
||||
open_on_setup = false,
|
||||
open_on_setup_file = false,
|
||||
open_on_tab = false,
|
||||
sort_by = "name",
|
||||
update_cwd = false,
|
||||
@ -415,6 +425,7 @@ function M.setup(conf)
|
||||
|
||||
_config.update_focused_file = opts.update_focused_file
|
||||
_config.open_on_setup = opts.open_on_setup
|
||||
_config.open_on_setup_file = opts.open_on_setup_file
|
||||
_config.ignore_buffer_on_setup = opts.ignore_buffer_on_setup
|
||||
_config.ignore_ft_on_setup = opts.ignore_ft_on_setup
|
||||
_config.hijack_directories = opts.hijack_directories
|
||||
|
||||
Loading…
Reference in New Issue
Block a user