feat: open tree on directory (#288)

This commit is contained in:
Kiyan
2021-08-28 11:39:10 +02:00
committed by GitHub
parent dc630d199a
commit 3bac5633e1
2 changed files with 74 additions and 18 deletions

View File

@@ -175,6 +175,21 @@ function M.print_clipboard()
fs.print_clipboard()
end
function M.hijack_current_window()
local View = require'nvim-tree.view'.View
if not View.bufnr then
View.bufnr = api.nvim_get_current_buf()
end
local current_tab = api.nvim_get_current_tabpage()
if not View.tabpages then
View.tabpages = {
[current_tab] = { winnr = api.nvim_get_current_win() }
}
else
View.tabpages[current_tab] = { winnr = api.nvim_get_current_win() }
end
end
function M.on_enter()
local bufnr = api.nvim_get_current_buf()
local bufname = api.nvim_buf_get_name(bufnr)
@@ -195,6 +210,9 @@ function M.on_enter()
local should_open = vim.g.nvim_tree_auto_open == 1
and ((is_dir and netrw_disabled) or (bufname == "" and not buf_has_content))
and not vim.tbl_contains(ft_ignore, buftype)
if bufname == '' or is_dir then
M.hijack_current_window()
end
lib.init(should_open, should_open)
end
@@ -260,6 +278,23 @@ local function update_root_dir()
lib.change_dir(new_cwd)
end
function M.open_on_directory()
local buf = api.nvim_get_current_buf()
local bufname = api.nvim_buf_get_name(buf)
if vim.fn.isdirectory(bufname) ~= 1 or bufname == lib.Tree.cwd then
return
end
if view.win_open() and #api.nvim_list_wins() > 1 then
view.close()
end
M.hijack_current_window()
lib.change_dir(bufname)
lib.set_index_and_redraw(bufname)
view.focus()
view.replace_window()
end
function M.buf_enter()
update_root_dir()
if vim.g.nvim_tree_follow == 1 then