#60 small refactoring: update teardown cleanup process
This commit is contained in:
@@ -9,6 +9,8 @@ LAZYGIT_BUFFER = nil
|
||||
LAZYGIT_LOADED = false
|
||||
vim.g.lazygit_opened = 0
|
||||
local prev_win = -1
|
||||
local win = -1
|
||||
local buffer = -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)
|
||||
@@ -16,14 +18,20 @@ local function on_exit(job_id, code, event)
|
||||
return
|
||||
end
|
||||
|
||||
vim.cmd('silent! :q')
|
||||
LAZYGIT_BUFFER = nil
|
||||
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_win_close(win, true)
|
||||
vim.api.nvim_set_current_win(prev_win)
|
||||
prev_win = -1
|
||||
if vim.api.nvim_buf_is_valid(buffer) and vim.api.nvim_buf_is_loaded(buffer) then
|
||||
vim.api.nvim_buf_delete(buffer, { force = true })
|
||||
end
|
||||
buffer = -1
|
||||
win = -1
|
||||
end
|
||||
end
|
||||
|
||||
@@ -47,7 +55,7 @@ local function lazygit(path)
|
||||
|
||||
prev_win = vim.api.nvim_get_current_win()
|
||||
|
||||
open_floating_window()
|
||||
win, buffer = open_floating_window()
|
||||
|
||||
local cmd = 'lazygit'
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ local function open_floating_window()
|
||||
LAZYGIT_LOADED = true
|
||||
end
|
||||
-- create file window, enter the window, and use the options defined in opts
|
||||
local _ = api.nvim_open_win(LAZYGIT_BUFFER, true, opts)
|
||||
local win = api.nvim_open_win(LAZYGIT_BUFFER, true, opts)
|
||||
|
||||
vim.bo[LAZYGIT_BUFFER].filetype = 'lazygit'
|
||||
|
||||
@@ -78,6 +78,8 @@ local function open_floating_window()
|
||||
vim.cmd(cmd)
|
||||
cmd = [[autocmd WinLeave <buffer> silent! execute 'silent bdelete! %s']]
|
||||
vim.cmd(cmd:format(border_buffer))
|
||||
|
||||
return win, border_window
|
||||
end
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user