start refresh. Need to find a way to trigger the function when FS is altered
This commit is contained in:
parent
083d2b556d
commit
98d94876f2
@ -64,7 +64,6 @@ local function set_mappings(edit_type)
|
|||||||
api.nvim_buf_set_keymap(buf, 'i', '<c-' ..v:upper()..'>', '', { nowait = true, noremap = true, silent = true })
|
api.nvim_buf_set_keymap(buf, 'i', '<c-' ..v:upper()..'>', '', { nowait = true, noremap = true, silent = true })
|
||||||
end
|
end
|
||||||
|
|
||||||
-- TODO: launch different functions here
|
|
||||||
if edit_type == 'add' then
|
if edit_type == 'add' then
|
||||||
api.nvim_buf_set_keymap(buf, 'i', '<CR>', "<esc>:lua require'lib/file'.add_file(vim.api.nvim_get_current_line())<CR>", { nowait = true, noremap = true, silent = true })
|
api.nvim_buf_set_keymap(buf, 'i', '<CR>', "<esc>:lua require'lib/file'.add_file(vim.api.nvim_get_current_line())<CR>", { nowait = true, noremap = true, silent = true })
|
||||||
elseif edit_type == 'rename' then
|
elseif edit_type == 'rename' then
|
||||||
|
|||||||
32
lua/tree.lua
32
lua/tree.lua
@ -62,7 +62,6 @@ local function create_nodes(path, depth, dirs)
|
|||||||
return sort_dirs(tree)
|
return sort_dirs(tree)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local function init_tree()
|
local function init_tree()
|
||||||
Tree = create_nodes(ROOT_PATH, 0, list_dirs())
|
Tree = create_nodes(ROOT_PATH, 0, list_dirs())
|
||||||
if ROOT_PATH ~= '/' then
|
if ROOT_PATH ~= '/' then
|
||||||
@ -152,6 +151,34 @@ local function update_view(update_cursor)
|
|||||||
end
|
end
|
||||||
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()
|
local function is_win_open()
|
||||||
return get_buf() ~= nil
|
return get_buf() ~= nil
|
||||||
end
|
end
|
||||||
@ -245,11 +272,14 @@ local function edit_file(edit_type)
|
|||||||
elseif edit_type == 'rename' then
|
elseif edit_type == 'rename' then
|
||||||
lib_file.edit_rename(node.name, node.path, node.dir)
|
lib_file.edit_rename(node.name, node.path, node.dir)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
refresh_tree()
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
toggle = toggle;
|
toggle = toggle;
|
||||||
open_file = open_file;
|
open_file = open_file;
|
||||||
edit_file = edit_file;
|
edit_file = edit_file;
|
||||||
|
refresh = refresh_tree;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -3,6 +3,9 @@ if exists('g:loaded_tree') | finish | endif
|
|||||||
let s:save_cpo = &cpo
|
let s:save_cpo = &cpo
|
||||||
set cpo&vim
|
set cpo&vim
|
||||||
|
|
||||||
|
let g:loaded_netrw = 1
|
||||||
|
let g:loaded_netrwPlugin = 1 " Disable netrw
|
||||||
|
|
||||||
hi def link LuaTreePopup Normal
|
hi def link LuaTreePopup Normal
|
||||||
hi def LuaTreeEndOfBuffer guifg=bg
|
hi def LuaTreeEndOfBuffer guifg=bg
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user