Add mapping for toggling ignored folders visibility.

This commit is contained in:
Kristijan Husak 2020-07-17 10:25:01 +02:00
parent 20f39a951a
commit 4f86707051
6 changed files with 33 additions and 17 deletions

View File

@ -44,12 +44,13 @@ let g:lua_tree_show_icons = {
" You don't have to define all keys. " You don't have to define all keys.
" NOTE: the 'edit' key will wrap/unwrap a folder and open a file " NOTE: the 'edit' key will wrap/unwrap a folder and open a file
let g:lua_tree_bindings = { let g:lua_tree_bindings = {
\ 'edit': '<CR>', \ 'edit': '<CR>',
\ 'edit_vsplit': '<C-v>', \ 'edit_vsplit': '<C-v>',
\ 'edit_split': '<C-x>', \ 'edit_split': '<C-x>',
\ 'edit_tab': '<C-t>', \ 'edit_tab': '<C-t>',
\ 'preview': '<Tab>', \ 'toggle_ignored': 'I',
\ 'cd': '<C-]>', \ 'preview': '<Tab>',
\ 'cd': '<C-]>',
} }
" Disable default mappings by plugin " Disable default mappings by plugin
@ -99,6 +100,7 @@ highlight LuaTreeFolderIcon guibg=blue
- `<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 |g:lua_tree_ignore|
- `gx` opens the file with the `open` command on MACOS and `xdg-open` in linux - `gx` opens the file with the `open` command on MACOS and `xdg-open` in linux
- Double left click acts like `<CR>` - Double left click acts like `<CR>`
- Double right click acts like `<C-]>` - Double right click acts like `<C-]>`

View File

@ -145,6 +145,7 @@ 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 |g:lua_tree_ignore|
- 'gx' opens the file with the `open` command on macos and `xdg-open` - 'gx' opens the file with the `open` command on macos and `xdg-open`
on linux. on linux.

View File

@ -45,15 +45,16 @@ end
function M.get_bindings() function M.get_bindings()
local keybindings = vim.g.lua_tree_bindings or {} local keybindings = vim.g.lua_tree_bindings or {}
return { return {
edit = keybindings.edit or '<CR>', edit = keybindings.edit or '<CR>',
edit_vsplit = keybindings.edit_vsplit or '<C-v>', edit_vsplit = keybindings.edit_vsplit or '<C-v>',
edit_split = keybindings.edit_split or '<C-x>', edit_split = keybindings.edit_split or '<C-x>',
edit_tab = keybindings.edit_tab or '<C-t>', edit_tab = keybindings.edit_tab or '<C-t>',
preview = keybindings.preview or '<Tab>', preview = keybindings.preview or '<Tab>',
cd = keybindings.cd or '<C-]>', toggle_ignored = keybindings.toggle_ignored or 'I',
create = keybindings.create or 'a', cd = keybindings.cd or '<C-]>',
remove = keybindings.remove or 'd', create = keybindings.create or 'a',
rename = keybindings.rename or 'r', remove = keybindings.remove or 'd',
rename = keybindings.rename or 'r',
} }
end end

View File

@ -205,6 +205,7 @@ local function set_mappings()
[bindings.edit_vsplit] = 'on_keypress("vsplit")'; [bindings.edit_vsplit] = 'on_keypress("vsplit")';
[bindings.edit_split] = 'on_keypress("split")'; [bindings.edit_split] = 'on_keypress("split")';
[bindings.edit_tab] = 'on_keypress("tabnew")'; [bindings.edit_tab] = 'on_keypress("tabnew")';
[bindings.toggle_ignored] = 'on_keypress("toggle_ignored")';
[bindings.create] = 'on_keypress("create")'; [bindings.create] = 'on_keypress("create")';
[bindings.remove] = 'on_keypress("remove")'; [bindings.remove] = 'on_keypress("remove")';
[bindings.rename] = 'on_keypress("rename")'; [bindings.rename] = 'on_keypress("rename")';
@ -278,4 +279,9 @@ function M.win_open()
return false return false
end end
function M.toggle_ignored()
pops.show_ignored = not pops.show_ignored
return M.refresh_tree()
end
return M return M

View File

@ -5,7 +5,9 @@ local icon_config = config.get_icon_state()
local api = vim.api local api = vim.api
local luv = vim.loop local luv = vim.loop
local M = {} local M = {
show_ignored = false
}
local path_to_matching_str = require'lib.utils'.path_to_matching_str local path_to_matching_str = require'lib.utils'.path_to_matching_str
@ -63,7 +65,7 @@ local function gen_ignore_check()
end end
return function(path) return function(path)
return ignore_list[path] == true return not M.show_ignored and ignore_list[path] == true
end end
end end

View File

@ -45,6 +45,10 @@ function M.on_keypress(mode)
return lib.open_file(mode, node.absolute_path) return lib.open_file(mode, node.absolute_path)
end end
if mode == 'toggle_ignored' then
return lib.toggle_ignored()
end
if node.name == ".." then if node.name == ".." then
return lib.change_dir("..") return lib.change_dir("..")
elseif mode == "cd" and node.entries ~= nil then elseif mode == "cd" and node.entries ~= nil then