diff --git a/lua/lazygit.lua b/lua/lazygit.lua index f1e0b2e..1e634eb 100644 --- a/lua/lazygit.lua +++ b/lua/lazygit.lua @@ -8,6 +8,7 @@ local fn = vim.fn LAZYGIT_BUFFER = nil LAZYGIT_LOADED = false vim.g.lazygit_opened = 0 +local prev_win = -1 --- on_exit callback function to delete the open buffer when lazygit exits in a neovim terminal local function on_exit(job_id, code, event) @@ -20,6 +21,10 @@ local function on_exit(job_id, code, event) LAZYGIT_LOADED = false vim.g.lazygit_opened = 0 vim.cmd('silent! :checktime') + if vim.api.nvim_win_is_valid(prev_win) then + vim.api.nvim_set_current_win(prev_win) + prev_win = -1 + end end --- Call lazygit @@ -40,6 +45,8 @@ local function lazygit(path) return end + prev_win = vim.api.nvim_get_current_win() + open_floating_window() local cmd = 'lazygit' @@ -69,6 +76,7 @@ local function lazygitfilter(path) if path == nil then path = project_root_dir() end + prev_win = vim.api.nvim_get_current_win() open_floating_window() local cmd = 'lazygit ' .. '-f ' .. path exec_lazygit_command(cmd)