From 41b050a6aba469371b5bd802a8a957c12a0da35c Mon Sep 17 00:00:00 2001 From: kiyan42 Date: Wed, 11 Mar 2020 12:06:42 +0100 Subject: [PATCH] Control how files are being opened --- README.md | 15 +++------------ lua/tree.lua | 16 +++++++++++++--- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 18e34ec4..1dfe4bf0 100644 --- a/README.md +++ b/README.md @@ -69,19 +69,10 @@ nnoremap n :LuaTreeFindFile ## TODO ### Perf / Fixes -- Tree creation should be async +- Tree creation could be async - 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 -- sneak like cd command to find a file/directory -- better default colors (use default vim groups) +- better default colors (use vim highlight groups) - create proper highlight groups or add highlight function to give the user ability to setup colors themselves - -### 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 - +- bufferize leafs of node being closed so when opening again the node, we open every directory that was previously open diff --git a/lua/tree.lua b/lua/tree.lua index 41ae3541..f5d78c27 100644 --- a/lua/tree.lua +++ b/lua/tree.lua @@ -53,6 +53,17 @@ if api.nvim_call_function('exists', { 'g:lua_tree_side' }) == 1 then 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 tree_index = api.nvim_win_get_cursor(0)[1] local tree = get_tree() @@ -93,16 +104,15 @@ local function open_file(open_type) init_tree(new_path) update_view() else - api.nvim_command('wincmd '..MOVE_TO..' | '..open_type..' '.. node.linkto) + create_new_buf(open_type, node.link_to); end elseif node.dir == true then if check_dir_access(node.path .. node.name) == false then return end open_dir(tree_index) update_view(true) - else - api.nvim_command('wincmd '..MOVE_TO..' | '..open_type..' '.. node.path .. node.name) + create_new_buf(open_type, node.path .. node.name); end end