feat: add update_focused_file.exclude (#2673)
* Add update_focused_file.exclude and move update_focused_file.ignore_list to update_focused_file.update_root.ignore_list * Pass ci checks * Add config migration for update_root and ignore_list * Missed one mention of update root in find_file.lua * Update migration code Co-authored-by: Alexander Courtis <alex@courtis.org> * make docs consistent * match on filename instead of entire path * exclude as a function * fix docs * default exclude value --------- Co-authored-by: Alexander Courtis <alex@courtis.org>
This commit is contained in:
parent
85c502e907
commit
e20966ae55
@ -500,9 +500,12 @@ Following is the default configuration. See |nvim-tree-opts| for details.
|
||||
},
|
||||
update_focused_file = {
|
||||
enable = false,
|
||||
update_root = false,
|
||||
update_root = {
|
||||
enable = false,
|
||||
ignore_list = {},
|
||||
},
|
||||
exclude = false,
|
||||
},
|
||||
system_open = {
|
||||
cmd = "",
|
||||
args = {},
|
||||
@ -1105,15 +1108,22 @@ Update the root directory of the tree if the file is not under current
|
||||
root directory. It prefers vim's cwd and `root_dirs`.
|
||||
Otherwise it falls back to the folder containing the file.
|
||||
Only relevant when `update_focused_file.enable` is `true`
|
||||
|
||||
*nvim-tree.update_focused_file.update_root.enable*
|
||||
Type: `boolean`, Default: `false`
|
||||
|
||||
*nvim-tree.update_focused_file.ignore_list*
|
||||
List of buffer names and filetypes that will not update the root dir
|
||||
of the tree if the file isn't found under the current root directory.
|
||||
Only relevant when `update_focused_file.update_root` and
|
||||
`update_focused_file.enable` are `true`.
|
||||
*nvim-tree.update_focused_file.update_root.ignore_list*
|
||||
List of buffer names and filetypes that will not update the root dir
|
||||
of the tree if the file isn't found under the current root directory.
|
||||
Only relevant when `update_focused_file.update_root.enable` and
|
||||
`update_focused_file.enable` are `true`.
|
||||
Type: {string}, Default: `{}`
|
||||
|
||||
*nvim-tree.update_focused_file.exclude*
|
||||
A function that returns true if the file should not be focused when opening.
|
||||
Takes the `BufEnter` event as an argument. see |autocmd-events|
|
||||
Type: {function}, Default: `false`
|
||||
|
||||
==============================================================================
|
||||
5.6 OPTS: SYSTEM OPEN *nvim-tree-opts-system-open*
|
||||
|
||||
@ -2869,8 +2879,10 @@ highlight group is not, hard linking as follows: >
|
||||
|nvim-tree.ui.confirm.remove|
|
||||
|nvim-tree.ui.confirm.trash|
|
||||
|nvim-tree.update_focused_file.enable|
|
||||
|nvim-tree.update_focused_file.ignore_list|
|
||||
|nvim-tree.update_focused_file.exclude|
|
||||
|nvim-tree.update_focused_file.update_root|
|
||||
|nvim-tree.update_focused_file.update_root.enable|
|
||||
|nvim-tree.update_focused_file.update_root.ignore_list|
|
||||
|nvim-tree.view.centralize_selection|
|
||||
|nvim-tree.view.cursorline|
|
||||
|nvim-tree.view.debounce_delay|
|
||||
|
||||
@ -27,7 +27,7 @@ function M.change_root(path, bufnr)
|
||||
-- skip if current file is in ignore_list
|
||||
if type(bufnr) == "number" then
|
||||
local ft = vim.api.nvim_buf_get_option(bufnr, "filetype") or ""
|
||||
for _, value in pairs(_config.update_focused_file.ignore_list) do
|
||||
for _, value in pairs(_config.update_focused_file.update_root.ignore_list) do
|
||||
if utils.str_find(path, value) or utils.str_find(ft, value) then
|
||||
return
|
||||
end
|
||||
@ -149,7 +149,7 @@ function M.change_dir(name)
|
||||
actions.root.change_dir.fn(name)
|
||||
end
|
||||
|
||||
if _config.update_focused_file.enable then
|
||||
if _config.update_focused_file.update_root.enable then
|
||||
actions.tree.find_file.fn()
|
||||
end
|
||||
end
|
||||
@ -247,7 +247,11 @@ local function setup_autocommands(opts)
|
||||
end
|
||||
if opts.update_focused_file.enable then
|
||||
create_nvim_tree_autocmd("BufEnter", {
|
||||
callback = function()
|
||||
callback = function(event)
|
||||
local exclude = opts.update_focused_file.exclude
|
||||
if type(exclude) == "function" and exclude(event) then
|
||||
return
|
||||
end
|
||||
utils.debounce("BufEnter:find_file", opts.view.debounce_delay, function()
|
||||
actions.tree.find_file.fn()
|
||||
end)
|
||||
@ -462,9 +466,12 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
|
||||
},
|
||||
update_focused_file = {
|
||||
enable = false,
|
||||
update_root = false,
|
||||
update_root = {
|
||||
enable = false,
|
||||
ignore_list = {},
|
||||
},
|
||||
exclude = false,
|
||||
},
|
||||
system_open = {
|
||||
cmd = "",
|
||||
args = {},
|
||||
@ -624,6 +631,9 @@ local ACCEPTED_TYPES = {
|
||||
group_empty = { "boolean", "function" },
|
||||
root_folder_label = { "function", "string", "boolean" },
|
||||
},
|
||||
update_focused_file = {
|
||||
exclude = { "function" },
|
||||
},
|
||||
filters = {
|
||||
custom = { "function" },
|
||||
},
|
||||
|
||||
@ -55,7 +55,7 @@ function M.fn(opts)
|
||||
end
|
||||
|
||||
-- update root
|
||||
if opts.update_root or M.config.update_focused_file.update_root then
|
||||
if opts.update_root or M.config.update_focused_file.update_root.enable then
|
||||
require("nvim-tree").change_root(path, bufnr)
|
||||
end
|
||||
|
||||
|
||||
@ -52,6 +52,14 @@ local function refactored(opts)
|
||||
if type(opts.renderer) == "table" and type(opts.renderer.highlight_git) == "boolean" then
|
||||
opts.renderer.highlight_git = opts.renderer.highlight_git and "name" or "none"
|
||||
end
|
||||
|
||||
-- 2024/02/15
|
||||
if type(opts.update_focused_file) == "table" then
|
||||
if type(opts.update_focused_file.update_root) ~= "table" then
|
||||
opts.update_focused_file.update_root = { enable = opts.update_focused_file.update_root }
|
||||
end
|
||||
end
|
||||
utils.move_missing_val(opts, "update_focused_file", "ignore_list", opts, "update_focused_file.update_root", "ignore_list", true)
|
||||
end
|
||||
|
||||
local function deprecated(opts)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user