Control how files are being opened

This commit is contained in:
kiyan42 2020-03-11 12:06:42 +01:00
parent b199763856
commit 41b050a6ab
2 changed files with 16 additions and 15 deletions

View File

@ -69,19 +69,10 @@ nnoremap <leader>n :LuaTreeFindFile<CR>
## TODO ## TODO
### Perf / Fixes ### Perf / Fixes
- Tree creation should be async - Tree creation could be async
- refactor all `system` call to `libuv` functions, with better error management - refactor all `system` call to `libuv` functions, with better error management
- bufferize leafs of node being closed so when opening again the node, we open every directory that was previously open
### Features ### Features
- sneak like cd command to find a file/directory - better default colors (use vim highlight groups)
- better default colors (use default vim groups)
- create proper highlight groups or add highlight function to give the user ability to setup colors themselves - create proper highlight groups or add highlight function to give the user ability to setup colors themselves
- bufferize leafs of node being closed so when opening again the node, we open every directory that was previously open
### Window Feature / Fixes
- opening help should open on the bottom
- better window management:
- check tree buffer/window for change so we can avoid it being resized or moved around or replaced by another file
- monitor window layout in current tab to open files in the right place
> this might be a little hard to implement since window layout events do not exist yet

View File

@ -53,6 +53,17 @@ if api.nvim_call_function('exists', { 'g:lua_tree_side' }) == 1 then
end end
end end
local function create_new_buf(open_type, bufname)
if open_type == 'edit' or open_type == 'split' then
api.nvim_command('wincmd '..MOVE_TO..' | '..open_type..' '..bufname)
elseif open_type == 'vsplit' then
local windows = api.nvim_list_wins();
api.nvim_command(#windows..'wincmd '..MOVE_TO..' | vsplit '..bufname)
elseif open_type == 'tabnew' then
api.nvim_command('tabnew '..bufname)
end
end
local function open_file(open_type) local function open_file(open_type)
local tree_index = api.nvim_win_get_cursor(0)[1] local tree_index = api.nvim_win_get_cursor(0)[1]
local tree = get_tree() local tree = get_tree()
@ -93,16 +104,15 @@ local function open_file(open_type)
init_tree(new_path) init_tree(new_path)
update_view() update_view()
else else
api.nvim_command('wincmd '..MOVE_TO..' | '..open_type..' '.. node.linkto) create_new_buf(open_type, node.link_to);
end end
elseif node.dir == true then elseif node.dir == true then
if check_dir_access(node.path .. node.name) == false then return end if check_dir_access(node.path .. node.name) == false then return end
open_dir(tree_index) open_dir(tree_index)
update_view(true) update_view(true)
else else
api.nvim_command('wincmd '..MOVE_TO..' | '..open_type..' '.. node.path .. node.name) create_new_buf(open_type, node.path .. node.name);
end end
end end