From 8967fb859919ca788f2ff53425e66b492fb75c50 Mon Sep 17 00:00:00 2001 From: TheBlob42 Date: Tue, 10 May 2022 08:07:45 +0200 Subject: [PATCH] feat: return to the previous window on exit Save the window from which the LazyGit command was executed and return to it on exit, so in case of multiple splits the user does not have to navigate back manually blub --- lua/lazygit.lua | 8 ++++++++ 1 file changed, 8 insertions(+) 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)