#857 add filter_custom action, filter_ignored->filter_git_ignored (#1077)

This commit is contained in:
Alexander Courtis
2022-03-18 21:30:30 +11:00
committed by GitHub
parent b136c7b6f9
commit a50fd77c99
6 changed files with 33 additions and 10 deletions

View File

@@ -282,7 +282,7 @@ local list = {
{ key = "<Tab>", action = "preview" }, { key = "<Tab>", action = "preview" },
{ key = "K", action = "first_sibling" }, { key = "K", action = "first_sibling" },
{ key = "J", action = "last_sibling" }, { key = "J", action = "last_sibling" },
{ key = "I", action = "toggle_ignored" }, { key = "I", action = "toggle_git_ignored" },
{ key = "H", action = "toggle_dotfiles" }, { key = "H", action = "toggle_dotfiles" },
{ key = "R", action = "refresh" }, { key = "R", action = "refresh" },
{ key = "a", action = "create" }, { key = "a", action = "create" },

View File

@@ -667,8 +667,9 @@ INFORMATIONS *nvim-tree-info*
- <C-x> will open the file in a horizontal split - <C-x> will open the file in a horizontal split
- <C-t> will open the file in a new tab - <C-t> will open the file in a new tab
- <Tab> will open the file as a preview (keeps the cursor in the tree) - <Tab> will open the file as a preview (keeps the cursor in the tree)
- `I` will toggle visibility of folders hidden via |git.ignore| option - `I` will toggle visibility of files/folders hidden via |git.ignore| option
- `H` will toggle visibility of dotfiles (files/folders starting with a `.`) - `H` will toggle visibility of dotfiles (files/folders starting with a `.`)
- U will toggle visibility of files/folders hidden via |filters.custom| option
- `R` will refresh the tree - `R` will refresh the tree
- Double left click acts like <CR> - Double left click acts like <CR>
- Double right click acts like <C-]> - Double right click acts like <C-]>
@@ -695,7 +696,7 @@ Defaults to:
{ key = "<Tab>", action = "preview" }, { key = "<Tab>", action = "preview" },
{ key = "K", action = "first_sibling" }, { key = "K", action = "first_sibling" },
{ key = "J", action = "last_sibling" }, { key = "J", action = "last_sibling" },
{ key = "I", action = "toggle_ignored" }, { key = "I", action = "toggle_git_ignored" },
{ key = "H", action = "toggle_dotfiles" }, { key = "H", action = "toggle_dotfiles" },
{ key = "R", action = "refresh" }, { key = "R", action = "refresh" },
{ key = "a", action = "create" }, { key = "a", action = "create" },
@@ -719,6 +720,7 @@ Defaults to:
{ key = "S", action = "search_node" }, { key = "S", action = "search_node" },
{ key = ".", action = "run_file_command" }, { key = ".", action = "run_file_command" },
{ key = "<C-k>", action = "toggle_file_info" } { key = "<C-k>", action = "toggle_file_info" }
{ key = "U", action = "toggle_custom" },
} }
< <
The `list` option in `view.mappings.list` is a table of The `list` option in `view.mappings.list` is a table of

View File

@@ -22,7 +22,7 @@ local M = {
{ key = "<Tab>", action = "preview" }, { key = "<Tab>", action = "preview" },
{ key = "K", action = "first_sibling" }, { key = "K", action = "first_sibling" },
{ key = "J", action = "last_sibling" }, { key = "J", action = "last_sibling" },
{ key = "I", action = "toggle_ignored" }, { key = "I", action = "toggle_git_ignored" },
{ key = "H", action = "toggle_dotfiles" }, { key = "H", action = "toggle_dotfiles" },
{ key = "R", action = "refresh" }, { key = "R", action = "refresh" },
{ key = "a", action = "create" }, { key = "a", action = "create" },
@@ -46,6 +46,7 @@ local M = {
{ key = "S", action = "search_node" }, { key = "S", action = "search_node" },
{ key = ".", action = "run_file_command" }, { key = ".", action = "run_file_command" },
{ key = "<C-k>", action = "toggle_file_info" }, { key = "<C-k>", action = "toggle_file_info" },
{ key = "U", action = "toggle_custom" },
}, },
custom_keypress_funcs = {}, custom_keypress_funcs = {},
} }
@@ -79,7 +80,8 @@ local keypress_funcs = {
system_open = require("nvim-tree.actions.system-open").fn, system_open = require("nvim-tree.actions.system-open").fn,
toggle_dotfiles = require("nvim-tree.actions.toggles").dotfiles, toggle_dotfiles = require("nvim-tree.actions.toggles").dotfiles,
toggle_help = require("nvim-tree.actions.toggles").help, toggle_help = require("nvim-tree.actions.toggles").help,
toggle_ignored = require("nvim-tree.actions.toggles").ignored, toggle_custom = require("nvim-tree.actions.toggles").custom,
toggle_git_ignored = require("nvim-tree.actions.toggles").git_ignored,
trash = require("nvim-tree.actions.trash").fn, trash = require("nvim-tree.actions.trash").fn,
} }

View File

@@ -5,8 +5,13 @@ local reloaders = require "nvim-tree.actions.reloaders"
local M = {} local M = {}
function M.ignored() function M.custom()
filters.config.filter_ignored = not filters.config.filter_ignored filters.config.filter_custom = not filters.config.filter_custom
return reloaders.reload_explorer()
end
function M.git_ignored()
filters.config.filter_git_ignored = not filters.config.filter_git_ignored
return reloaders.reload_explorer() return reloaders.reload_explorer()
end end

View File

@@ -30,7 +30,7 @@ function M.should_ignore(path)
end end
end end
if not M.config.filter_ignored then if not M.config.filter_custom then
return false return false
end end
@@ -50,14 +50,14 @@ function M.should_ignore(path)
end end
function M.should_ignore_git(path, status) function M.should_ignore_git(path, status)
return M.config.filter_ignored return M.config.filter_git_ignored
and (M.config.filter_git_ignored and status and status[path] == "!!") and (M.config.filter_git_ignored and status and status[path] == "!!")
and not is_excluded(path) and not is_excluded(path)
end end
function M.setup(opts) function M.setup(opts)
M.config = { M.config = {
filter_ignored = true, filter_custom = true,
filter_dotfiles = opts.filters.dotfiles, filter_dotfiles = opts.filters.dotfiles,
filter_git_ignored = opts.git.ignore, filter_git_ignored = opts.git.ignore,
} }

View File

@@ -180,6 +180,7 @@ local migrations = {
function M.migrate_legacy_options(opts) function M.migrate_legacy_options(opts)
local msg = nil local msg = nil
-- g: options
for g, m in pairs(migrations) do for g, m in pairs(migrations) do
if vim.fn.exists("g:" .. g) ~= 0 then if vim.fn.exists("g:" .. g) ~= 0 then
m(opts) m(opts)
@@ -190,6 +191,19 @@ function M.migrate_legacy_options(opts)
if msg then if msg then
require("nvim-tree.utils").warn(msg) require("nvim-tree.utils").warn(msg)
end end
-- regular opts
if opts.view then
if opts.view.mappings then
if opts.view.mappings.list then
for _, m in pairs(opts.view.mappings.list) do
if m.action == "toggle_ignored" then
m.action = "toggle_git_ignored"
end
end
end
end
end
end end
return M return M