From 3a2f68b9d53fdf360beba222022868c527ae4d8a Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Tue, 18 Oct 2022 11:14:35 +1100 Subject: [PATCH] fix(#1668): revert all startup behaviour changes back to 540055b --- doc/nvim-tree-lua.txt | 28 ++++++++-------------------- lua/nvim-tree.lua | 13 +++++-------- lua/nvim-tree/legacy.lua | 5 +++++ 3 files changed, 18 insertions(+), 28 deletions(-) diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index 58d8a458..7d4a082d 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -175,7 +175,6 @@ Subsequent calls to setup will replace the previous configuration. open_on_setup = false, open_on_setup_file = false, open_on_tab = false, - focus_empty_on_setup = false, ignore_buf_on_tab_change = {}, sort_by = "name", root_dirs = {}, @@ -391,33 +390,28 @@ Hijack netrw windows (overridden if |disable_netrw| is `true`) Type: `boolean`, Default: `true` *nvim-tree.open_on_setup* -Will automatically open the tree when running setup if startup buffer is a -directory, empty or unnamed. -nvim-tree window will be focused. -See |nvim-tree.focus_empty_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* -Will automatically open the tree when running setup if startup buffer is a -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 |nvim-tree.update_focused_file| is enabled. +File will be found if update_focused_file is enabled. Type: `boolean`, Default: `false` *nvim-tree.ignore_buffer_on_setup* -Always open the tree when |nvim-tree.open_on_setup| is enabled, regardless of -the startup buffer. -Buffer window will be focused. +Will ignore the buffer, when deciding to open the tree on setup. Type: `boolean`, Default: `false` *nvim-tree.ignore_ft_on_setup* -List of filetypes that will prevent |nvim-tree.open_on_setup_file|. +List of filetypes that will prevent `open_on_setup` to open. You can use this option if you don't want the tree to open in some scenarios (eg using vim startify). Type: {string}, Default: `{}` *nvim-tree.ignore_buf_on_tab_change* -List of filetypes or buffer names that will prevent |nvim-tree.open_on_tab|. +List of filetypes or buffer names that will prevent `open_on_tab` to open. Type: {string}, Default: `{}` *nvim-tree.auto_reload_on_write* @@ -434,11 +428,6 @@ Opens the tree automatically when switching tabpage or opening a new tabpage if the tree was previously open. Type: `boolean`, Default: `false` -*nvim-tree.focus_empty_on_setup* -When the tree opens as a result of |nvim-tree.open_on_setup| or -|nvim-tree.open_on_tab| and the buffer is empty, focus the buffer. - Type: `boolean`, Default: `false` - *nvim-tree.sort_by* Changes how files within the same directory are sorted. Can be one of `name`, `case_sensitive`, `modification_time`, `extension` or a @@ -491,8 +480,7 @@ Will change cwd of nvim-tree to that of new buffer's when opening nvim-tree. Type: `boolean`, Default: `false` *nvim-tree.hijack_directories* (previously `update_to_buf_dir`) -hijacks new directory buffers when they are opened (`:e dir`) or if a -directory is opened on startup e.g. `nvim .` +hijacks new directory buffers when they are opened (`:e dir`). *nvim-tree.hijack_directories.enable* Enable the feature. diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index 47b18622..3eec3114 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -135,7 +135,8 @@ end local function find_existing_windows() return vim.tbl_filter(function(win) - return utils.is_nvim_tree_buf(api.nvim_win_get_buf(win)) + local buf = api.nvim_win_get_buf(win) + return api.nvim_buf_get_name(buf):match "NvimTree" ~= nil end, api.nvim_list_wins()) end @@ -236,22 +237,20 @@ function M.on_enter(netrw_disabled) local buf_has_content = #lines > 1 or (#lines == 1 and lines[1] ~= "") local buf_is_dir = is_dir and netrw_disabled + local buf_is_empty = bufname == "" and not buf_has_content local should_be_preserved = vim.tbl_contains(ft_ignore, buftype) local should_open = false local should_focus_other_window = false local should_find = false if (_config.open_on_setup or _config.open_on_setup_file) and not should_be_preserved then - if not buf_has_content and _config.open_on_setup then - should_open = true - should_focus_other_window = _config.focus_empty_on_setup - elseif buf_is_dir and _config.open_on_setup 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 and _config.open_on_setup then + elseif _config.ignore_buffer_on_setup then should_open = true should_focus_other_window = true end @@ -459,7 +458,6 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS open_on_setup = false, open_on_setup_file = false, open_on_tab = false, - focus_empty_on_setup = false, ignore_buf_on_tab_change = {}, sort_by = "name", root_dirs = {}, @@ -734,7 +732,6 @@ 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.focus_empty_on_setup = opts.focus_empty_on_setup _config.ignore_buffer_on_setup = opts.ignore_buffer_on_setup _config.ignore_ft_on_setup = opts.ignore_ft_on_setup _config.ignore_buf_on_tab_change = opts.ignore_buf_on_tab_change diff --git a/lua/nvim-tree/legacy.lua b/lua/nvim-tree/legacy.lua index 7f803f73..7ee3a9ea 100644 --- a/lua/nvim-tree/legacy.lua +++ b/lua/nvim-tree/legacy.lua @@ -295,6 +295,11 @@ local function removed(opts) utils.notify.warn "auto close feature has been removed, see note in the README (tips & reminder section)" opts.auto_close = nil end + + if opts.focus_empty_on_setup then + utils.notify.warn "focus_empty_on_setup has been removed and will be replaced by a new startup configuration. Please remove this option. See https://bit.ly/3S7BtqP and https://bit.ly/3yJch2T" + end + opts.focus_empty_on_setup = nil end function M.migrate_legacy_options(opts)