Merge pull request #72 from thefux/bug/60-fix-lazygit-telescope-extension
Bug/60 fix lazygit telescope extension
This commit is contained in:
@@ -10,6 +10,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)
|
||||
@@ -17,14 +19,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
|
||||
|
||||
@@ -48,7 +56,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 {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
local pickers = require("telescope.pickers")
|
||||
local finders = require("telescope.finders")
|
||||
local action_set = require("telescope.actions.set")
|
||||
local actions = require("telescope.actions")
|
||||
local action_state = require("telescope.actions.state")
|
||||
local conf = require("telescope.config").values
|
||||
local lazygit_utils = require("lazygit.utils")
|
||||
@@ -72,8 +72,15 @@ local lazygit_repos = function(opts)
|
||||
end,
|
||||
},
|
||||
sorter = conf.generic_sorter(opts),
|
||||
attach_mappings = function(_, _)
|
||||
action_set.select:replace(open_lazygit)
|
||||
attach_mappings = function(prompt_buf, _)
|
||||
actions.select_default:replace(function ()
|
||||
-- for what ever reason any attempt to open an external window (such as lazygit)
|
||||
-- shall be done after closing the buffer manually
|
||||
actions.close(prompt_buf)
|
||||
|
||||
open_lazygit()
|
||||
end
|
||||
)
|
||||
return true
|
||||
end
|
||||
}):find()
|
||||
|
||||
Reference in New Issue
Block a user