Add close_node action to close parent directory
This commit is contained in:
parent
2bf0043409
commit
54403415ed
@ -183,6 +183,7 @@ INFORMATIONS *nvim-tree-info*
|
||||
- move around like in any vim buffer
|
||||
- '<CR>' on '..' will cd in the above directory
|
||||
- typing '<C-]>' will cd in the directory under the cursor
|
||||
- typing '<BS>' will close current opened directory or parent
|
||||
|
||||
- type 'a' to add a file
|
||||
- type 'r' to rename a file
|
||||
@ -219,6 +220,7 @@ default keybindings will be applied to undefined keys.
|
||||
\ edit_vsplit: '<c-v>',
|
||||
\ edit_split: '<c-x>',
|
||||
\ edit_tab: '<c-t>',
|
||||
\ close_node: ['<s-cr>', '<bs>'],
|
||||
\ cd: '<c-]>',
|
||||
\ preview: '<Tab>',
|
||||
\ create: 'a',
|
||||
|
||||
@ -55,6 +55,7 @@ function M.get_bindings()
|
||||
edit_vsplit = keybindings.edit_vsplit or '<C-v>',
|
||||
edit_split = keybindings.edit_split or '<C-x>',
|
||||
edit_tab = keybindings.edit_tab or '<C-t>',
|
||||
close_node = keybindings.close_node or {'<S-CR>', '<BS>'},
|
||||
preview = keybindings.preview or '<Tab>',
|
||||
toggle_ignored = keybindings.toggle_ignored or 'I',
|
||||
toggle_dotfiles = keybindings.toggle_dotfiles or 'H',
|
||||
|
||||
@ -238,6 +238,7 @@ local function set_mappings()
|
||||
[bindings.edit_vsplit] = 'on_keypress("vsplit")';
|
||||
[bindings.edit_split] = 'on_keypress("split")';
|
||||
[bindings.edit_tab] = 'on_keypress("tabnew")';
|
||||
[bindings.close_node] = 'on_keypress("close_node")';
|
||||
[bindings.toggle_ignored] = 'on_keypress("toggle_ignored")';
|
||||
[bindings.toggle_dotfiles] = 'on_keypress("toggle_dotfiles")';
|
||||
[bindings.refresh] = 'on_keypress("refresh")';
|
||||
@ -310,6 +311,41 @@ function M.open()
|
||||
api.nvim_command('setlocal '..window_opts.split_command)
|
||||
end
|
||||
|
||||
function M.close_node(node)
|
||||
if node.name == '..' then return end
|
||||
|
||||
local sep = '/'
|
||||
local dname = node.absolute_path:match("(.*"..sep..")")
|
||||
local index = 2
|
||||
|
||||
local function iter(entries)
|
||||
for _, entry in ipairs(entries) do
|
||||
if dname:match('^'..entry.match_path..sep..'$') ~= nil then
|
||||
return entry
|
||||
end
|
||||
|
||||
index = index + 1
|
||||
if entry.open == true then
|
||||
local child = iter(entry.entries)
|
||||
if child ~= nil then return child end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if node.open == true then
|
||||
node.open = false
|
||||
else
|
||||
local parent = iter(M.Tree.entries)
|
||||
if parent == nil then
|
||||
index = 1
|
||||
else
|
||||
parent.open = false
|
||||
end
|
||||
api.nvim_win_set_cursor(M.Tree.winnr(), {index, 0})
|
||||
end
|
||||
renderer.draw(M.Tree, true)
|
||||
end
|
||||
|
||||
function M.win_open()
|
||||
return M.Tree.winnr() ~= nil
|
||||
end
|
||||
|
||||
@ -65,6 +65,7 @@ local keypress_funcs = {
|
||||
copy = fs.copy,
|
||||
cut = fs.cut,
|
||||
paste = fs.paste,
|
||||
close_node = lib.close_node,
|
||||
toggle_ignored = lib.toggle_ignored,
|
||||
toggle_dotfiles = lib.toggle_dotfiles,
|
||||
refresh = lib.refresh_tree,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user