Merge pull request #61 from TheBlob42/master
feat: return to the previous window on exit
This commit is contained in:
@@ -8,6 +8,7 @@ local fn = vim.fn
|
|||||||
LAZYGIT_BUFFER = nil
|
LAZYGIT_BUFFER = nil
|
||||||
LAZYGIT_LOADED = false
|
LAZYGIT_LOADED = false
|
||||||
vim.g.lazygit_opened = 0
|
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
|
--- on_exit callback function to delete the open buffer when lazygit exits in a neovim terminal
|
||||||
local function on_exit(job_id, code, event)
|
local function on_exit(job_id, code, event)
|
||||||
@@ -20,6 +21,10 @@ local function on_exit(job_id, code, event)
|
|||||||
LAZYGIT_LOADED = false
|
LAZYGIT_LOADED = false
|
||||||
vim.g.lazygit_opened = 0
|
vim.g.lazygit_opened = 0
|
||||||
vim.cmd('silent! :checktime')
|
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
|
end
|
||||||
|
|
||||||
--- Call lazygit
|
--- Call lazygit
|
||||||
@@ -40,6 +45,8 @@ local function lazygit(path)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
prev_win = vim.api.nvim_get_current_win()
|
||||||
|
|
||||||
open_floating_window()
|
open_floating_window()
|
||||||
|
|
||||||
local cmd = 'lazygit'
|
local cmd = 'lazygit'
|
||||||
@@ -69,6 +76,7 @@ local function lazygitfilter(path)
|
|||||||
if path == nil then
|
if path == nil then
|
||||||
path = project_root_dir()
|
path = project_root_dir()
|
||||||
end
|
end
|
||||||
|
prev_win = vim.api.nvim_get_current_win()
|
||||||
open_floating_window()
|
open_floating_window()
|
||||||
local cmd = 'lazygit ' .. '-f ' .. path
|
local cmd = 'lazygit ' .. '-f ' .. path
|
||||||
exec_lazygit_command(cmd)
|
exec_lazygit_command(cmd)
|
||||||
|
|||||||
Reference in New Issue
Block a user