Add close_node action to close parent directory
This commit is contained in:
@@ -183,6 +183,7 @@ INFORMATIONS *nvim-tree-info*
|
|||||||
- move around like in any vim buffer
|
- move around like in any vim buffer
|
||||||
- '<CR>' on '..' will cd in the above directory
|
- '<CR>' on '..' will cd in the above directory
|
||||||
- typing '<C-]>' will cd in the directory under the cursor
|
- 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 'a' to add a file
|
||||||
- type 'r' to rename 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_vsplit: '<c-v>',
|
||||||
\ edit_split: '<c-x>',
|
\ edit_split: '<c-x>',
|
||||||
\ edit_tab: '<c-t>',
|
\ edit_tab: '<c-t>',
|
||||||
|
\ close_node: ['<s-cr>', '<bs>'],
|
||||||
\ cd: '<c-]>',
|
\ cd: '<c-]>',
|
||||||
\ preview: '<Tab>',
|
\ preview: '<Tab>',
|
||||||
\ create: 'a',
|
\ create: 'a',
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ function M.get_bindings()
|
|||||||
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>',
|
||||||
|
close_node = keybindings.close_node or {'<S-CR>', '<BS>'},
|
||||||
preview = keybindings.preview or '<Tab>',
|
preview = keybindings.preview or '<Tab>',
|
||||||
toggle_ignored = keybindings.toggle_ignored or 'I',
|
toggle_ignored = keybindings.toggle_ignored or 'I',
|
||||||
toggle_dotfiles = keybindings.toggle_dotfiles or 'H',
|
toggle_dotfiles = keybindings.toggle_dotfiles or 'H',
|
||||||
|
|||||||
@@ -238,6 +238,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.close_node] = 'on_keypress("close_node")';
|
||||||
[bindings.toggle_ignored] = 'on_keypress("toggle_ignored")';
|
[bindings.toggle_ignored] = 'on_keypress("toggle_ignored")';
|
||||||
[bindings.toggle_dotfiles] = 'on_keypress("toggle_dotfiles")';
|
[bindings.toggle_dotfiles] = 'on_keypress("toggle_dotfiles")';
|
||||||
[bindings.refresh] = 'on_keypress("refresh")';
|
[bindings.refresh] = 'on_keypress("refresh")';
|
||||||
@@ -310,6 +311,41 @@ function M.open()
|
|||||||
api.nvim_command('setlocal '..window_opts.split_command)
|
api.nvim_command('setlocal '..window_opts.split_command)
|
||||||
end
|
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()
|
function M.win_open()
|
||||||
return M.Tree.winnr() ~= nil
|
return M.Tree.winnr() ~= nil
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ local keypress_funcs = {
|
|||||||
copy = fs.copy,
|
copy = fs.copy,
|
||||||
cut = fs.cut,
|
cut = fs.cut,
|
||||||
paste = fs.paste,
|
paste = fs.paste,
|
||||||
|
close_node = lib.close_node,
|
||||||
toggle_ignored = lib.toggle_ignored,
|
toggle_ignored = lib.toggle_ignored,
|
||||||
toggle_dotfiles = lib.toggle_dotfiles,
|
toggle_dotfiles = lib.toggle_dotfiles,
|
||||||
refresh = lib.refresh_tree,
|
refresh = lib.refresh_tree,
|
||||||
|
|||||||
Reference in New Issue
Block a user