From 1fe29f8eef4d81536b74dd3dcb23c837f66b10a5 Mon Sep 17 00:00:00 2001 From: kiyan Date: Sat, 5 Feb 2022 18:42:08 +0100 Subject: [PATCH] chore: move g:nvim_tree_quit_on_open into open_file action config --- README.md | 4 +++- doc/nvim-tree-lua.txt | 17 +++++++++-------- lua/nvim-tree.lua | 21 ++++++--------------- lua/nvim-tree/actions/change-dir.lua | 6 +----- lua/nvim-tree/actions/init.lua | 1 + lua/nvim-tree/actions/open-file.lua | 15 ++++++++++----- lua/nvim-tree/view.lua | 11 +++++------ 7 files changed, 35 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index 5965727c..8adb4484 100644 --- a/README.md +++ b/README.md @@ -100,6 +100,9 @@ require'nvim-tree'.setup { actions = { change_dir = { 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. 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 -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_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. diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index 4a45ef33..1fd68afb 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -130,7 +130,10 @@ function. actions = { change_dir = { 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` 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* @@ -458,13 +466,6 @@ You can set icons for: You can enable file highlight for git attributes by setting this property. 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* Can be `0` or `1`. When `1`, will display indent markers when folders are open diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index 41370f00..a0304e10 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -330,7 +330,10 @@ local DEFAULT_OPTS = { }, actions = { 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.open_on_setup = opts.open_on_setup _config.ignore_ft_on_setup = opts.ignore_ft_on_setup - if type(opts.update_to_buf_dir) == "boolean" then - 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 + _config.update_to_buf_dir = opts.update_to_buf_dir require'nvim-tree.colors'.setup() 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.explorer'.setup(opts) require'nvim-tree.git'.setup(opts) diff --git a/lua/nvim-tree/actions/change-dir.lua b/lua/nvim-tree/actions/change-dir.lua index 0d5fa5f2..cf82759c 100644 --- a/lua/nvim-tree/actions/change-dir.lua +++ b/lua/nvim-tree/actions/change-dir.lua @@ -27,11 +27,7 @@ function M.fn(name) end function M.setup(options) - if options.actions.change_dir.global ~= nil then - M.options.global = options.actions.change_dir.global - else - M.options.global = vim.g.nvim_tree_change_dir_global == 1 - end + M.options.global = options.actions.change_dir.global end return M diff --git a/lua/nvim-tree/actions/init.lua b/lua/nvim-tree/actions/init.lua index 7263f7ab..5fa20aa4 100644 --- a/lua/nvim-tree/actions/init.lua +++ b/lua/nvim-tree/actions/init.lua @@ -169,6 +169,7 @@ local DEFAULT_MAPPING_CONFIG = { function M.setup(opts) require'nvim-tree.actions.system-open'.setup(opts.system_open) 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 options = vim.tbl_deep_extend('force', DEFAULT_MAPPING_CONFIG, user_map_config) diff --git a/lua/nvim-tree/actions/open-file.lua b/lua/nvim-tree/actions/open-file.lua index 0c1ac12b..62852813 100644 --- a/lua/nvim-tree/actions/open-file.lua +++ b/lua/nvim-tree/actions/open-file.lua @@ -5,7 +5,9 @@ local lib = require'nvim-tree.lib' local utils = require'nvim-tree.utils' 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 ---tabpage that aren't NvimTree. @@ -88,8 +90,7 @@ local function pick_window() end local function open_file_in_tab(filename) - local close = vim.g.nvim_tree_quit_on_open == 1 - if close then + if M.quit_on_open then view.close() else -- 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) end - if not close then + if not M.quit_on_open then vim.cmd("wincmd p") end @@ -194,9 +195,13 @@ function M.fn(mode, filename) return end - if vim.g.nvim_tree_quit_on_open == 1 then + if M.quit_on_open then view.close() end end +function M.setup(opts) + M.quit_on_open = opts.actions.open_file.quit_on_open +end + return M diff --git a/lua/nvim-tree/view.lua b/lua/nvim-tree/view.lua index be266f80..e4087fa4 100644 --- a/lua/nvim-tree/view.lua +++ b/lua/nvim-tree/view.lua @@ -72,19 +72,21 @@ local DEFAULT_CONFIG = { } 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.width = options.width M.View.height = options.height 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.relativenumber = options.relativenumber M.View.winopts.signcolumn = options.signcolumn vim.cmd "augroup NvimTreeView" 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 "augroup END" @@ -127,9 +129,6 @@ function M._prevent_buffer_override() end vim.cmd("buffer "..curbuf) M.resize() - if vim.g.nvim_tree_quit_on_open == 1 then - M.close() - end end) end