preserve previous focus (#841)
This commit is contained in:
committed by
GitHub
parent
9e2f6b6f25
commit
9c0f410c50
@@ -7,6 +7,7 @@ function M.nvim_tree_callback(callback_name)
|
|||||||
end
|
end
|
||||||
|
|
||||||
M.View = {
|
M.View = {
|
||||||
|
last_focused_winnr = nil,
|
||||||
bufnr = nil,
|
bufnr = nil,
|
||||||
tabpages = {},
|
tabpages = {},
|
||||||
hide_root_folder = false,
|
hide_root_folder = false,
|
||||||
@@ -312,6 +313,7 @@ local function is_buf_valid(bufnr)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function M.open(options)
|
function M.open(options)
|
||||||
|
M.View.last_focused_winnr = a.nvim_get_current_win()
|
||||||
local should_redraw = false
|
local should_redraw = false
|
||||||
if not is_buf_valid(M.View.bufnr) then
|
if not is_buf_valid(M.View.bufnr) then
|
||||||
should_redraw = true
|
should_redraw = true
|
||||||
@@ -355,9 +357,13 @@ function M.close()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
local tree_win = M.get_winnr()
|
local tree_win = M.get_winnr()
|
||||||
|
local current_win = a.nvim_get_current_win()
|
||||||
for _, win in pairs(a.nvim_list_wins()) do
|
for _, win in pairs(a.nvim_list_wins()) do
|
||||||
if tree_win ~= win and a.nvim_win_get_config(win).relative == "" then
|
if tree_win ~= win and a.nvim_win_get_config(win).relative == "" then
|
||||||
a.nvim_win_hide(tree_win)
|
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
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user