From c42a27ef20a4a3ead0cff070fae7583a2921e43a Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Sun, 13 Mar 2022 14:25:30 +1100 Subject: [PATCH 1/2] 857 add filter_custom action, filter_ignored->filter_git_ignored --- README.md | 2 +- doc/nvim-tree-lua.txt | 4 +++- lua/nvim-tree/actions/init.lua | 6 ++++-- lua/nvim-tree/actions/toggles.lua | 9 +++++++-- lua/nvim-tree/explorer/filters.lua | 6 +++--- lua/nvim-tree/legacy.lua | 14 ++++++++++++++ 6 files changed, 32 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index e82093cb601..765d6b815ae 100644 --- a/README.md +++ b/README.md @@ -282,7 +282,7 @@ local list = { { key = "", action = "preview" }, { key = "K", action = "first_sibling" }, { key = "J", action = "last_sibling" }, - { key = "I", action = "toggle_ignored" }, + { key = "I", action = "toggle_git_ignored" }, { key = "H", action = "toggle_dotfiles" }, { key = "R", action = "refresh" }, { key = "a", action = "create" }, diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index 76d46d04026..8904b43f98f 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -665,6 +665,7 @@ INFORMATIONS *nvim-tree-info* - will open the file as a preview (keeps the cursor in the tree) - `I` will toggle visibility of folders hidden via |git.ignore| option - `H` will toggle visibility of dotfiles (files/folders starting with a `.`) +- U will toggle visibility of files/folders matching |filters.custom| option - `R` will refresh the tree - Double left click acts like - Double right click acts like @@ -691,7 +692,7 @@ Defaults to: { key = "", action = "preview" }, { key = "K", action = "first_sibling" }, { key = "J", action = "last_sibling" }, - { key = "I", action = "toggle_ignored" }, + { key = "I", action = "toggle_git_ignored" }, { key = "H", action = "toggle_dotfiles" }, { key = "R", action = "refresh" }, { key = "a", action = "create" }, @@ -715,6 +716,7 @@ Defaults to: { key = "S", action = "search_node" }, { key = ".", action = "run_file_command" }, { key = "", action = "toggle_file_info" } + { key = "U", action = "toggle_custom" }, } < The `list` option in `view.mappings.list` is a table of diff --git a/lua/nvim-tree/actions/init.lua b/lua/nvim-tree/actions/init.lua index af230f381d8..d049a29a432 100644 --- a/lua/nvim-tree/actions/init.lua +++ b/lua/nvim-tree/actions/init.lua @@ -22,7 +22,7 @@ local M = { { key = "", action = "preview" }, { key = "K", action = "first_sibling" }, { key = "J", action = "last_sibling" }, - { key = "I", action = "toggle_ignored" }, + { key = "I", action = "toggle_git_ignored" }, { key = "H", action = "toggle_dotfiles" }, { key = "R", action = "refresh" }, { key = "a", action = "create" }, @@ -46,6 +46,7 @@ local M = { { key = "S", action = "search_node" }, { key = ".", action = "run_file_command" }, { key = "", action = "toggle_file_info" }, + { key = "U", action = "toggle_custom" }, }, custom_keypress_funcs = {}, } @@ -79,7 +80,8 @@ local keypress_funcs = { system_open = require("nvim-tree.actions.system-open").fn, toggle_dotfiles = require("nvim-tree.actions.toggles").dotfiles, 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, } diff --git a/lua/nvim-tree/actions/toggles.lua b/lua/nvim-tree/actions/toggles.lua index d6b302bb1c8..fb4a9db2709 100644 --- a/lua/nvim-tree/actions/toggles.lua +++ b/lua/nvim-tree/actions/toggles.lua @@ -5,8 +5,13 @@ local reloaders = require "nvim-tree.actions.reloaders" local M = {} -function M.ignored() - filters.config.filter_ignored = not filters.config.filter_ignored +function M.custom() + 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() end diff --git a/lua/nvim-tree/explorer/filters.lua b/lua/nvim-tree/explorer/filters.lua index 27cd2eeb67c..958a9a9bccc 100644 --- a/lua/nvim-tree/explorer/filters.lua +++ b/lua/nvim-tree/explorer/filters.lua @@ -30,7 +30,7 @@ function M.should_ignore(path) end end - if not M.config.filter_ignored then + if not M.config.filter_custom then return false end @@ -50,14 +50,14 @@ function M.should_ignore(path) end 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 not is_excluded(path) end function M.setup(opts) M.config = { - filter_ignored = true, + filter_custom = true, filter_dotfiles = opts.filters.dotfiles, filter_git_ignored = opts.git.ignore, } diff --git a/lua/nvim-tree/legacy.lua b/lua/nvim-tree/legacy.lua index 391e6ac5ae4..7507557c873 100644 --- a/lua/nvim-tree/legacy.lua +++ b/lua/nvim-tree/legacy.lua @@ -180,6 +180,7 @@ local migrations = { function M.migrate_legacy_options(opts) local msg = nil + -- g: options for g, m in pairs(migrations) do if vim.fn.exists("g:" .. g) ~= 0 then m(opts) @@ -190,6 +191,19 @@ function M.migrate_legacy_options(opts) if msg then require("nvim-tree.utils").warn(msg) 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 return M From fa8797ef95644212163c8275f1c12566dd93f729 Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Sun, 13 Mar 2022 14:41:56 +1100 Subject: [PATCH 2/2] 857 add filter_custom action, filter_ignored->filter_git_ignored --- doc/nvim-tree-lua.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index 8904b43f98f..2e5a938fb74 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -663,9 +663,9 @@ INFORMATIONS *nvim-tree-info* - will open the file in a horizontal split - will open the file in a new 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 `.`) -- U will toggle visibility of files/folders matching |filters.custom| option +- U will toggle visibility of files/folders hidden via |filters.custom| option - `R` will refresh the tree - Double left click acts like - Double right click acts like