From 03168a5155850d7e5325bb552ee7e7345c99a73e Mon Sep 17 00:00:00 2001 From: kyazdani42 Date: Sun, 1 Mar 2020 19:23:42 +0100 Subject: [PATCH] fix tree when option is 'right' --- lua/lib/winutils.lua | 14 ++++++++++---- lua/tree.lua | 11 +++++++++-- plugin/tree.vim | 4 ++++ 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/lua/lib/winutils.lua b/lua/lib/winutils.lua index d0bb2a2f..572a353b 100644 --- a/lua/lib/winutils.lua +++ b/lua/lib/winutils.lua @@ -35,9 +35,8 @@ end local BUF_OPTIONS = { 'nowrap', 'sidescroll=5', 'nospell', 'nolist', 'nofoldenable', 'foldmethod=manual', 'foldcolumn=0', 'nonumber', 'norelativenumber', - 'winfixwidth', 'winfixheight', 'noswapfile', 'bufhidden=wipe', - 'splitbelow', 'splitright', 'winhighlight=EndOfBuffer:LuaTreeEndOfBuffer', - 'noshowmode', 'noruler', 'noshowcmd', + 'winfixwidth', 'winfixheight', 'noswapfile', 'splitbelow', 'noruler', + 'noshowmode', 'noshowcmd' } local WIN_WIDTH = 30 @@ -55,7 +54,7 @@ end local function open() local options = { - bufhidden = 'delete'; + bufhidden = 'wipe'; buftype = 'nowrite'; modifiable = false; } @@ -71,9 +70,16 @@ local function open() api.nvim_command('wincmd '..SIDE) api.nvim_command('vertical resize '..WIN_WIDTH) api.nvim_win_set_buf(0, buf) + + api.nvim_command('setlocal winhighlight=EndOfBuffer:LuaTreeEndOfBuffer') for _, opt in pairs(BUF_OPTIONS) do api.nvim_command('setlocal '..opt) end + if SIDE == 'L' then + api.nvim_command('setlocal nosplitright') + else + api.nvim_command('setlocal splitright') + end end local function replace_tree() diff --git a/lua/tree.lua b/lua/tree.lua index 49664eaf..359926c0 100644 --- a/lua/tree.lua +++ b/lua/tree.lua @@ -45,6 +45,13 @@ local function toggle() end end +local MOVE_TO = 'l' +if api.nvim_call_function('exists', { 'g:lua_tree_side' }) == 1 then + if api.nvim_get_var('lua_tree_side') == 'right' then + MOVE_TO = 'h' + end +end + local function open_file(open_type) local tree_index = api.nvim_win_get_cursor(0)[1] local tree = get_tree() @@ -85,7 +92,7 @@ local function open_file(open_type) init_tree(new_path) update_view() else - api.nvim_command('wincmd l | '..open_type..' '.. node.linkto) + api.nvim_command('wincmd '..MOVE_TO..' | '..open_type..' '.. node.linkto) end elseif node.dir == true then @@ -94,7 +101,7 @@ local function open_file(open_type) update_view(true) else - api.nvim_command('wincmd l | '..open_type..' '.. node.path .. node.name) + api.nvim_command('wincmd '..MOVE_TO..' | '..open_type..' '.. node.path .. node.name) end end diff --git a/plugin/tree.vim b/plugin/tree.vim index e1bfb57d..6033867b 100644 --- a/plugin/tree.vim +++ b/plugin/tree.vim @@ -12,6 +12,10 @@ au BufWritePost * lua require'tree'.refresh() au BufEnter * lua require'tree'.check_windows_and_close() au VimEnter * lua require'tree'.check_buffer_and_open() +" TODO set status line dynamically on bufenter in the luatree +" to remove lightline and other possible components +au BufEnter LuaTree setlocal statusline="" + if get(g:, 'lua_tree_follow') != 0 au BufEnter * :LuaTreeFindFile endif