chore: move g:nvim_tree_quit_on_open into open_file action config

This commit is contained in:
kiyan 2022-02-05 18:42:08 +01:00
parent 756b7acc52
commit 1fe29f8eef
7 changed files with 35 additions and 40 deletions

View File

@ -100,6 +100,9 @@ require'nvim-tree'.setup {
actions = { actions = {
change_dir = { change_dir = {
global = false, global = false,
},
open_file = {
quit_on_open = false,
} }
} }
} }
@ -108,7 +111,6 @@ require'nvim-tree'.setup {
These additional options must be set **BEFORE** calling `require'nvim-tree'` or calling setup. These additional options must be set **BEFORE** calling `require'nvim-tree'` or calling setup.
They are being migrated to the setup function bit by bit, check [this issue](https://github.com/kyazdani42/nvim-tree.lua/issues/674) if you encounter any problems related to configs not working after update. They are being migrated to the setup function bit by bit, check [this issue](https://github.com/kyazdani42/nvim-tree.lua/issues/674) if you encounter any problems related to configs not working after update.
```vim ```vim
let g:nvim_tree_quit_on_open = 1 "0 by default, closes the tree when you open a file
let g:nvim_tree_indent_markers = 1 "0 by default, this option shows indent markers when folders are open let g:nvim_tree_indent_markers = 1 "0 by default, this option shows indent markers when folders are open
let g:nvim_tree_git_hl = 1 "0 by default, will enable file highlight for git attributes (can be used without the icons). let g:nvim_tree_git_hl = 1 "0 by default, will enable file highlight for git attributes (can be used without the icons).
let g:nvim_tree_highlight_opened_files = 1 "0 by default, will enable folder and file icon highlight for opened files/directories. let g:nvim_tree_highlight_opened_files = 1 "0 by default, will enable folder and file icon highlight for opened files/directories.

View File

@ -130,7 +130,10 @@ function.
actions = { actions = {
change_dir = { change_dir = {
global = false, global = false,
} },
open_file = {
quit_on_open = false,
},
} }
} }
< <
@ -368,6 +371,11 @@ Here is a list of the options available in the setup call:
type: `boolean` type: `boolean`
default: `false` default: `false`
- |actions.open_file.quit_on_open|: closes the explorer when opening a file.
It will also disable preventing a buffer overriding the tree.
type: `boolean`
default: `false`
============================================================================== ==============================================================================
OPTIONS *nvim-tree-options* OPTIONS *nvim-tree-options*
@ -458,13 +466,6 @@ You can set icons for:
You can enable file highlight for git attributes by setting this property. You can enable file highlight for git attributes by setting this property.
This can be used with or without the icons. This can be used with or without the icons.
|g:nvim_tree_quit_on_open| *g:nvim_tree_quit_on_open*
Can be `0` or `1`. When `1`, will close the tree when a file is opened.
Applies to: `edit`, `vsplit`, `split`, `tabnew`.
Default is 0
|g:nvim_tree_indent_markers| *g:nvim_tree_indent_markers* |g:nvim_tree_indent_markers| *g:nvim_tree_indent_markers*
Can be `0` or `1`. When `1`, will display indent markers when folders are open Can be `0` or `1`. When `1`, will display indent markers when folders are open

View File

@ -330,7 +330,10 @@ local DEFAULT_OPTS = {
}, },
actions = { actions = {
change_dir = { change_dir = {
global = false, global = vim.g.nvim_tree_change_dir_global == 1,
},
open_file = {
quit_on_open = vim.g.nvim_tree_quit_on_open == 1,
} }
} }
} }
@ -343,23 +346,11 @@ function M.setup(conf)
_config.update_focused_file = opts.update_focused_file _config.update_focused_file = opts.update_focused_file
_config.open_on_setup = opts.open_on_setup _config.open_on_setup = opts.open_on_setup
_config.ignore_ft_on_setup = opts.ignore_ft_on_setup _config.ignore_ft_on_setup = opts.ignore_ft_on_setup
if type(opts.update_to_buf_dir) == "boolean" then _config.update_to_buf_dir = opts.update_to_buf_dir
utils.warn("update_to_buf_dir is now a table, see :help nvim-tree.update_to_buf_dir")
_config.update_to_buf_dir = {
enable = opts.update_to_buf_dir,
auto_open = opts.update_to_buf_dir,
}
else
_config.update_to_buf_dir = opts.update_to_buf_dir
end
if opts.lsp_diagnostics ~= nil then
utils.warn("setup.lsp_diagnostics has been removed, see :help nvim-tree.diagnostics")
end
require'nvim-tree.colors'.setup() require'nvim-tree.colors'.setup()
require'nvim-tree.actions'.setup(opts) require'nvim-tree.actions'.setup(opts)
require'nvim-tree.view'.setup(opts.view or {}) require'nvim-tree.view'.setup(opts or {})
require'nvim-tree.diagnostics'.setup(opts) require'nvim-tree.diagnostics'.setup(opts)
require'nvim-tree.explorer'.setup(opts) require'nvim-tree.explorer'.setup(opts)
require'nvim-tree.git'.setup(opts) require'nvim-tree.git'.setup(opts)

View File

@ -27,11 +27,7 @@ function M.fn(name)
end end
function M.setup(options) function M.setup(options)
if options.actions.change_dir.global ~= nil then M.options.global = options.actions.change_dir.global
M.options.global = options.actions.change_dir.global
else
M.options.global = vim.g.nvim_tree_change_dir_global == 1
end
end end
return M return M

View File

@ -169,6 +169,7 @@ local DEFAULT_MAPPING_CONFIG = {
function M.setup(opts) function M.setup(opts)
require'nvim-tree.actions.system-open'.setup(opts.system_open) require'nvim-tree.actions.system-open'.setup(opts.system_open)
require'nvim-tree.actions.trash'.setup(opts.trash) require'nvim-tree.actions.trash'.setup(opts.trash)
require'nvim-tree.actions.open-file'.setup(opts)
local user_map_config = (opts.view or {}).mappings or {} local user_map_config = (opts.view or {}).mappings or {}
local options = vim.tbl_deep_extend('force', DEFAULT_MAPPING_CONFIG, user_map_config) local options = vim.tbl_deep_extend('force', DEFAULT_MAPPING_CONFIG, user_map_config)

View File

@ -5,7 +5,9 @@ local lib = require'nvim-tree.lib'
local utils = require'nvim-tree.utils' local utils = require'nvim-tree.utils'
local view = require'nvim-tree.view' local view = require'nvim-tree.view'
local M = {} local M = {
quit_on_open = false,
}
---Get user to pick a window. Selectable windows are all windows in the current ---Get user to pick a window. Selectable windows are all windows in the current
---tabpage that aren't NvimTree. ---tabpage that aren't NvimTree.
@ -88,8 +90,7 @@ local function pick_window()
end end
local function open_file_in_tab(filename) local function open_file_in_tab(filename)
local close = vim.g.nvim_tree_quit_on_open == 1 if M.quit_on_open then
if close then
view.close() view.close()
else else
-- Switch window first to ensure new window doesn't inherit settings from -- Switch window first to ensure new window doesn't inherit settings from
@ -114,7 +115,7 @@ local function open_file_in_tab(filename)
api.nvim_set_current_buf(alt_bufid) api.nvim_set_current_buf(alt_bufid)
end end
if not close then if not M.quit_on_open then
vim.cmd("wincmd p") vim.cmd("wincmd p")
end end
@ -194,9 +195,13 @@ function M.fn(mode, filename)
return return
end end
if vim.g.nvim_tree_quit_on_open == 1 then if M.quit_on_open then
view.close() view.close()
end end
end end
function M.setup(opts)
M.quit_on_open = opts.actions.open_file.quit_on_open
end
return M return M

View File

@ -72,19 +72,21 @@ local DEFAULT_CONFIG = {
} }
function M.setup(opts) function M.setup(opts)
local options = vim.tbl_deep_extend('force', DEFAULT_CONFIG, opts) local options = vim.tbl_deep_extend('force', DEFAULT_CONFIG, opts.view or {})
M.View.side = options.side M.View.side = options.side
M.View.width = options.width M.View.width = options.width
M.View.height = options.height M.View.height = options.height
M.View.hide_root_folder = options.hide_root_folder M.View.hide_root_folder = options.hide_root_folder
M.View.auto_resize = opts.auto_resize M.View.auto_resize = options.auto_resize
M.View.winopts.number = options.number M.View.winopts.number = options.number
M.View.winopts.relativenumber = options.relativenumber M.View.winopts.relativenumber = options.relativenumber
M.View.winopts.signcolumn = options.signcolumn M.View.winopts.signcolumn = options.signcolumn
vim.cmd "augroup NvimTreeView" vim.cmd "augroup NvimTreeView"
vim.cmd "au!" vim.cmd "au!"
vim.cmd "au BufWinEnter,BufWinLeave * lua require'nvim-tree.view'._prevent_buffer_override()" if not opts.actions.open_file.quit_on_open then
vim.cmd "au BufWinEnter,BufWinLeave * lua require'nvim-tree.view'._prevent_buffer_override()"
end
vim.cmd "au BufEnter,BufNewFile * lua require'nvim-tree'.open_on_directory()" vim.cmd "au BufEnter,BufNewFile * lua require'nvim-tree'.open_on_directory()"
vim.cmd "augroup END" vim.cmd "augroup END"
@ -127,9 +129,6 @@ function M._prevent_buffer_override()
end end
vim.cmd("buffer "..curbuf) vim.cmd("buffer "..curbuf)
M.resize() M.resize()
if vim.g.nvim_tree_quit_on_open == 1 then
M.close()
end
end) end)
end end