Skip to content

Commit 41b050a

Browse files
committed
Control how files are being opened
1 parent b199763 commit 41b050a

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

README.md

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,10 @@ nnoremap <leader>n :LuaTreeFindFile<CR>
6969
## TODO
7070

7171
### Perf / Fixes
72-
- Tree creation should be async
72+
- Tree creation could be async
7373
- refactor all `system` call to `libuv` functions, with better error management
74-
- bufferize leafs of node being closed so when opening again the node, we open every directory that was previously open
7574

7675
### Features
77-
- sneak like cd command to find a file/directory
78-
- better default colors (use default vim groups)
76+
- better default colors (use vim highlight groups)
7977
- create proper highlight groups or add highlight function to give the user ability to setup colors themselves
80-
81-
### Window Feature / Fixes
82-
- opening help should open on the bottom
83-
- better window management:
84-
- check tree buffer/window for change so we can avoid it being resized or moved around or replaced by another file
85-
- monitor window layout in current tab to open files in the right place
86-
> this might be a little hard to implement since window layout events do not exist yet
87-
78+
- bufferize leafs of node being closed so when opening again the node, we open every directory that was previously open

lua/tree.lua

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,17 @@ if api.nvim_call_function('exists', { 'g:lua_tree_side' }) == 1 then
5353
end
5454
end
5555

56+
local function create_new_buf(open_type, bufname)
57+
if open_type == 'edit' or open_type == 'split' then
58+
api.nvim_command('wincmd '..MOVE_TO..' | '..open_type..' '..bufname)
59+
elseif open_type == 'vsplit' then
60+
local windows = api.nvim_list_wins();
61+
api.nvim_command(#windows..'wincmd '..MOVE_TO..' | vsplit '..bufname)
62+
elseif open_type == 'tabnew' then
63+
api.nvim_command('tabnew '..bufname)
64+
end
65+
end
66+
5667
local function open_file(open_type)
5768
local tree_index = api.nvim_win_get_cursor(0)[1]
5869
local tree = get_tree()
@@ -93,16 +104,15 @@ local function open_file(open_type)
93104
init_tree(new_path)
94105
update_view()
95106
else
96-
api.nvim_command('wincmd '..MOVE_TO..' | '..open_type..' '.. node.linkto)
107+
create_new_buf(open_type, node.link_to);
97108
end
98109

99110
elseif node.dir == true then
100111
if check_dir_access(node.path .. node.name) == false then return end
101112
open_dir(tree_index)
102113
update_view(true)
103-
104114
else
105-
api.nvim_command('wincmd '..MOVE_TO..' | '..open_type..' '.. node.path .. node.name)
115+
create_new_buf(open_type, node.path .. node.name);
106116
end
107117
end
108118

0 commit comments

Comments
 (0)