Merge pull request #16 from kdheepak/kd/change-floating-window-persistence
This commit is contained in:
@@ -2,7 +2,8 @@ vim = vim
|
|||||||
local api = vim.api
|
local api = vim.api
|
||||||
local fn = vim.fn
|
local fn = vim.fn
|
||||||
|
|
||||||
FILE_BUFFER = nil
|
LAZYGIT_BUFFER = nil
|
||||||
|
LAZYGIT_LOADED = false
|
||||||
|
|
||||||
--- Strip leading and lagging whitespace
|
--- Strip leading and lagging whitespace
|
||||||
local function trim(str)
|
local function trim(str)
|
||||||
@@ -37,9 +38,10 @@ end
|
|||||||
--- 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)
|
||||||
if code == 0 then
|
if code == 0 then
|
||||||
-- delete terminal buffer
|
-- Close the window where the LAZYGIT_BUFFER is
|
||||||
vim.cmd("silent! bdelete!")
|
vim.cmd("silent! :q")
|
||||||
FILE_BUFFER = nil
|
LAZYGIT_BUFFER = nil
|
||||||
|
LAZYGIT_LOADED = false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -53,9 +55,11 @@ end
|
|||||||
|
|
||||||
--- Call lazygit
|
--- Call lazygit
|
||||||
local function exec_lazygit_command(cmd)
|
local function exec_lazygit_command(cmd)
|
||||||
cmd = git_editor_prefix(cmd)
|
if LAZYGIT_LOADED == false then
|
||||||
-- ensure that the buffer is closed on exit
|
cmd = git_editor_prefix(cmd)
|
||||||
vim.fn.termopen(cmd, { on_exit = on_exit })
|
-- ensure that the buffer is closed on exit
|
||||||
|
vim.fn.termopen(cmd, { on_exit = on_exit })
|
||||||
|
end
|
||||||
vim.cmd "startinsert"
|
vim.cmd "startinsert"
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -111,20 +115,25 @@ local function open_floating_window()
|
|||||||
vim.cmd 'set winhl=Normal:Floating'
|
vim.cmd 'set winhl=Normal:Floating'
|
||||||
|
|
||||||
-- create a unlisted scratch buffer
|
-- create a unlisted scratch buffer
|
||||||
if FILE_BUFFER == nil then
|
if LAZYGIT_BUFFER == nil then
|
||||||
FILE_BUFFER = api.nvim_create_buf(false, true)
|
LAZYGIT_BUFFER = api.nvim_create_buf(false, true)
|
||||||
|
else
|
||||||
|
LAZYGIT_LOADED = true
|
||||||
end
|
end
|
||||||
-- create file window, enter the window, and use the options defined in opts
|
-- create file window, enter the window, and use the options defined in opts
|
||||||
local file_window = api.nvim_open_win(FILE_BUFFER, true, opts)
|
local file_window = api.nvim_open_win(LAZYGIT_BUFFER, true, opts)
|
||||||
|
|
||||||
vim.bo[FILE_BUFFER].filetype = 'lazygit'
|
vim.bo[LAZYGIT_BUFFER].filetype = 'lazygit'
|
||||||
|
|
||||||
|
vim.cmd('setlocal bufhidden=hide')
|
||||||
vim.cmd('setlocal nocursorcolumn')
|
vim.cmd('setlocal nocursorcolumn')
|
||||||
vim.cmd('set winblend=' .. vim.g.lazygit_floating_window_winblend)
|
vim.cmd('set winblend=' .. vim.g.lazygit_floating_window_winblend)
|
||||||
|
|
||||||
-- use autocommand to ensure that the border_buffer closes at the same time as the main buffer
|
-- use autocommand to ensure that the border_buffer closes at the same time as the main buffer
|
||||||
local cmd = [[autocmd WinLeave <buffer> silent! execute 'silent bdelete! %s %s']]
|
local cmd = [[autocmd WinLeave <buffer> silent! execute 'hide']]
|
||||||
vim.cmd(cmd:format(FILE_BUFFER, border_buffer))
|
vim.cmd(cmd)
|
||||||
|
local cmd = [[autocmd WinLeave <buffer> silent! execute 'silent bdelete! %s']]
|
||||||
|
vim.cmd(cmd:format(border_buffer))
|
||||||
end
|
end
|
||||||
|
|
||||||
--- :LazyGit entry point
|
--- :LazyGit entry point
|
||||||
|
|||||||
Reference in New Issue
Block a user