feat(actions): expand all under folder (#1292)
This commit is contained in:
parent
0373680819
commit
3a95c5a9cf
@ -190,6 +190,9 @@ require'nvim-tree'.setup { -- BEGIN_DEFAULT_OPTS
|
||||
global = false,
|
||||
restrict_above_cwd = false,
|
||||
},
|
||||
expand_all = {
|
||||
max_folder_discovery = 300,
|
||||
},
|
||||
open_file = {
|
||||
quit_on_open = false,
|
||||
resize_window = true,
|
||||
@ -261,6 +264,7 @@ require'nvim-tree'.setup { -- BEGIN_DEFAULT_OPTS
|
||||
- Double left click acts like `<CR>`
|
||||
- Double right click acts like `<C-]>`
|
||||
- `W` will collapse the whole tree
|
||||
- `E` will expand the whole tree. Be aware this might hang neovim for a while if running on a big folder (see `:help nvim-tree.actions.expand_all.max_folder_discovery`).
|
||||
- `S` will prompt the user to enter a path and then expands the tree to match the path
|
||||
- `.` will enter vim command mode with the file the cursor is on
|
||||
- `C-k` will toggle a popup with file infos about the file under the cursor
|
||||
@ -331,6 +335,7 @@ local list = {
|
||||
{ key = "q", action = "close" },
|
||||
{ key = "g?", action = "toggle_help" },
|
||||
{ key = "W", action = "collapse_all" },
|
||||
{ key = "E", action = "expand_all" },
|
||||
{ key = "S", action = "search_node" },
|
||||
{ key = "<C-k>", action = "toggle_file_info" },
|
||||
{ key = ".", action = "run_file_command" }
|
||||
|
||||
@ -208,6 +208,9 @@ Values may be functions. Warning: this may result in unexpected behaviour.
|
||||
global = false,
|
||||
restrict_above_cwd = false,
|
||||
},
|
||||
expand_all = {
|
||||
max_folder_discovery = 300,
|
||||
},
|
||||
open_file = {
|
||||
quit_on_open = false,
|
||||
resize_window = true,
|
||||
@ -633,6 +636,11 @@ Configuration for various actions.
|
||||
Restrict changing to a directory above the global current working directory.
|
||||
Type: `boolean`, Default: `false`
|
||||
|
||||
*nvim-tree.actions.expand_all.max_folder_discovery*
|
||||
Limit the number of folders being explored when expanding every folders.
|
||||
Avoids hanging neovim when running this action on very large folders.
|
||||
Type: `number`, Default: `300`
|
||||
|
||||
*nvim-tree.actions.open_file.quit_on_open*
|
||||
Closes the explorer when opening a file.
|
||||
It will also disable preventing a buffer overriding the tree.
|
||||
@ -762,6 +770,8 @@ INFORMATIONS *nvim-tree-info*
|
||||
- Double left click acts like <CR>
|
||||
- Double right click acts like <C-]>
|
||||
- `W` will collapse the whole tree
|
||||
- `E` will expand the whole tree. Be aware this might hang neovim for a while
|
||||
if running on a big folder (such as home dir or root dir).
|
||||
- `S` will prompt the user to enter a path and then expands the tree to match the path
|
||||
- `.` will enter vim command mode with the file the cursor is on
|
||||
- `C-k` will toggle a popup with file infos about the file under the cursor
|
||||
@ -807,6 +817,7 @@ Defaults to:
|
||||
{ key = "q", action = "close" },
|
||||
{ key = "g?", action = "toggle_help" },
|
||||
{ key = 'W', action = "collapse_all" },
|
||||
{ key = 'E', action = "expand_all" },
|
||||
{ key = "S", action = "search_node" },
|
||||
{ key = ".", action = "run_file_command" },
|
||||
{ key = "<C-k>", action = "toggle_file_info" }
|
||||
|
||||
@ -465,6 +465,9 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
|
||||
global = false,
|
||||
restrict_above_cwd = false,
|
||||
},
|
||||
expand_all = {
|
||||
max_folder_discovery = 300,
|
||||
},
|
||||
open_file = {
|
||||
quit_on_open = false,
|
||||
resize_window = true,
|
||||
|
||||
56
lua/nvim-tree/actions/expand-all.lua
Normal file
56
lua/nvim-tree/actions/expand-all.lua
Normal file
@ -0,0 +1,56 @@
|
||||
local core = require "nvim-tree.core"
|
||||
local renderer = require "nvim-tree.renderer"
|
||||
local utils = require "nvim-tree.utils"
|
||||
|
||||
local M = {}
|
||||
|
||||
local function expand(node)
|
||||
node.open = true
|
||||
if #node.nodes == 0 then
|
||||
core.get_explorer():expand(node)
|
||||
end
|
||||
end
|
||||
|
||||
local function gen_iterator()
|
||||
local expansion_count = 0
|
||||
|
||||
local function iterate(parent)
|
||||
if expansion_count >= M.MAX_FOLDER_DISCOVERY then
|
||||
return true
|
||||
end
|
||||
|
||||
if parent.parent and parent.nodes and not parent.open then
|
||||
expansion_count = expansion_count + 1
|
||||
expand(parent)
|
||||
end
|
||||
|
||||
for _, node in pairs(parent.nodes) do
|
||||
if node.nodes and not node.open then
|
||||
expansion_count = expansion_count + 1
|
||||
expand(node)
|
||||
end
|
||||
|
||||
if node.open then
|
||||
if iterate(node) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return iterate
|
||||
end
|
||||
|
||||
function M.fn(base_node)
|
||||
local node = base_node.nodes and base_node or core.get_explorer()
|
||||
if gen_iterator()(node) then
|
||||
utils.warn("expansion iteration was halted after " .. M.MAX_FOLDER_DISCOVERY .. " discovered folders")
|
||||
end
|
||||
renderer.draw()
|
||||
end
|
||||
|
||||
function M.setup(opts)
|
||||
M.MAX_FOLDER_DISCOVERY = opts.actions.expand_all.max_folder_discovery
|
||||
end
|
||||
|
||||
return M
|
||||
@ -45,6 +45,7 @@ local M = {
|
||||
{ key = "q", action = "close" },
|
||||
{ key = "g?", action = "toggle_help" },
|
||||
{ key = "W", action = "collapse_all" },
|
||||
{ key = "E", action = "expand_all" },
|
||||
{ key = "S", action = "search_node" },
|
||||
{ key = ".", action = "run_file_command" },
|
||||
{ key = "<C-k>", action = "toggle_file_info" },
|
||||
@ -57,6 +58,7 @@ local keypress_funcs = {
|
||||
close = view.close,
|
||||
close_node = require("nvim-tree.actions.movements").parent_node(true),
|
||||
collapse_all = require("nvim-tree.actions.collapse-all").fn,
|
||||
expand_all = require("nvim-tree.actions.expand-all").fn,
|
||||
copy_absolute_path = require("nvim-tree.actions.copy-paste").copy_absolute_path,
|
||||
copy_name = require("nvim-tree.actions.copy-paste").copy_filename,
|
||||
copy_path = require("nvim-tree.actions.copy-paste").copy_path,
|
||||
@ -237,6 +239,7 @@ function M.setup(opts)
|
||||
require("nvim-tree.actions.change-dir").setup(opts)
|
||||
require("nvim-tree.actions.copy-paste").setup(opts)
|
||||
require("nvim-tree.actions.create-file").setup(opts)
|
||||
require("nvim-tree.actions.expand-all").setup(opts)
|
||||
|
||||
local user_map_config = (opts.view or {}).mappings or {}
|
||||
local options = vim.tbl_deep_extend("force", DEFAULT_MAPPING_CONFIG, user_map_config)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user