preserve previous focus (#841)

This commit is contained in:
Carlos Coves Prieto 2022-01-21 10:57:50 +01:00 committed by GitHub
parent 9e2f6b6f25
commit 9c0f410c50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,6 +7,7 @@ function M.nvim_tree_callback(callback_name)
end
M.View = {
last_focused_winnr = nil,
bufnr = nil,
tabpages = {},
hide_root_folder = false,
@ -312,6 +313,7 @@ local function is_buf_valid(bufnr)
end
function M.open(options)
M.View.last_focused_winnr = a.nvim_get_current_win()
local should_redraw = false
if not is_buf_valid(M.View.bufnr) then
should_redraw = true
@ -355,9 +357,13 @@ function M.close()
end
end
local tree_win = M.get_winnr()
local current_win = a.nvim_get_current_win()
for _, win in pairs(a.nvim_list_wins()) do
if tree_win ~= win and a.nvim_win_get_config(win).relative == "" then
a.nvim_win_hide(tree_win)
if tree_win == current_win and M.View.last_focus_winnr then
a.nvim_set_current_win(M.View.last_focus_winnr)
end
return
end
end