diff --git a/lua/lib/file.lua b/lua/lib/file.lua index 8f4b96b5..4bb0fb26 100644 --- a/lua/lib/file.lua +++ b/lua/lib/file.lua @@ -64,7 +64,6 @@ local function set_mappings(edit_type) api.nvim_buf_set_keymap(buf, 'i', '', '', { nowait = true, noremap = true, silent = true }) end - -- TODO: launch different functions here if edit_type == 'add' then api.nvim_buf_set_keymap(buf, 'i', '', ":lua require'lib/file'.add_file(vim.api.nvim_get_current_line())", { nowait = true, noremap = true, silent = true }) elseif edit_type == 'rename' then diff --git a/lua/tree.lua b/lua/tree.lua index 815befb9..bae20e66 100644 --- a/lua/tree.lua +++ b/lua/tree.lua @@ -62,7 +62,6 @@ local function create_nodes(path, depth, dirs) return sort_dirs(tree) end - local function init_tree() Tree = create_nodes(ROOT_PATH, 0, list_dirs()) if ROOT_PATH ~= '/' then @@ -152,6 +151,34 @@ local function update_view(update_cursor) end end +local function refresh_tree() + local cache = {} + + for _, v in pairs(Tree) do + if v.dir == true and v.open == true then + table.insert(cache, v.path .. v.name) + end + end + + init_tree() + + for i, node in pairs(Tree) do + if node.dir == true then + for _, path in pairs(cache) do + if node.path .. node.name == path then + node.open = true + local dirs = list_dirs(path) + for j, n in pairs(create_nodes(path, node.depth + 1, dirs)) do + table.insert(Tree, i + j, n) + end + end + end + end + end + + update_view() +end + local function is_win_open() return get_buf() ~= nil end @@ -245,11 +272,14 @@ local function edit_file(edit_type) elseif edit_type == 'rename' then lib_file.edit_rename(node.name, node.path, node.dir) end + + refresh_tree() end return { toggle = toggle; open_file = open_file; edit_file = edit_file; + refresh = refresh_tree; } diff --git a/plugin/tree.vim b/plugin/tree.vim index cab011c7..e23fa74e 100644 --- a/plugin/tree.vim +++ b/plugin/tree.vim @@ -3,6 +3,9 @@ if exists('g:loaded_tree') | finish | endif let s:save_cpo = &cpo set cpo&vim +let g:loaded_netrw = 1 +let g:loaded_netrwPlugin = 1 " Disable netrw + hi def link LuaTreePopup Normal hi def LuaTreeEndOfBuffer guifg=bg