diff --git a/README.md b/README.md index 379ad74c..4de6f8c8 100644 --- a/README.md +++ b/README.md @@ -17,10 +17,9 @@ - [x] Mouse support ## TODO -- handle permissions properly (display error on Read access denied) -- fix all window problems (force size to stay always the same and keep it on the left) -- kill window when its the last one (BufLeave) -- open automatically when opening neovim with `nvim` or `nvim .` +- display error on Read access denied (and better handling of errors if any) +- fix all window problems (force size to stay always the same and keep it on the side) +- add options for users - cd command to move faster accross the fs if needed - quickly find file in the directory structure - use libuv functions instead of `touch` and `mkdir` in `add_file()` diff --git a/lua/tree.lua b/lua/tree.lua index 9ed7d004..cc61a99c 100644 --- a/lua/tree.lua +++ b/lua/tree.lua @@ -119,10 +119,26 @@ local function refresh() end end +local function check_windows_and_close() + local wins = api.nvim_list_wins() + + if #wins == 1 and is_win_open() then + -- TODO: find why it hangs + api.nvim_command('q!') + end +end + +local function check_buffer_and_open() + local bufname = api.nvim_buf_get_name(0) + if bufname == '' or is_dir(bufname) then toggle() end +end + return { toggle = toggle; open_file = open_file; edit_file = edit_file; refresh = refresh; + check_windows_and_close = check_windows_and_close; + check_buffer_and_open = check_buffer_and_open; } diff --git a/plugin/tree.vim b/plugin/tree.vim index 64887f51..302d2ada 100644 --- a/plugin/tree.vim +++ b/plugin/tree.vim @@ -4,11 +4,13 @@ let s:save_cpo = &cpo set cpo&vim let g:loaded_netrw = 1 -let g:loaded_netrwPlugin = 1 " Disable netrw +let g:loaded_netrwPlugin = 1 hi def link LuaTreePopup Normal au BufWritePost * lua require'tree'.refresh() +au BufEnter * lua require'tree'.check_windows_and_close() +au VimEnter * lua require'tree'.check_buffer_and_open() command! LuaTree lua require'tree'.toggle()