fix: create new terminal if old isn't valid anymore

This commit is contained in:
Matej Janezic 2025-10-11 20:35:04 +02:00
parent 5149c12b9a
commit d076dcf093
Signed by: janezicmatej
GPG Key ID: 4298E230ED37B2C0
1 changed files with 12 additions and 1 deletions

View File

@ -5,9 +5,20 @@
---@type table<number, TermBuf> ---@type table<number, TermBuf>
local state = {} local state = {}
---@param n integer
local function get_from_state(n)
local term_buf = state[n]
if term_buf ~= nil and vim.api.nvim_buf_is_valid(term_buf.buf_id) then
return term_buf
end
state[n] = nil
return nil
end
---@param n integer ---@param n integer
local function get_or_create_term(n) local function get_or_create_term(n)
if state[n] ~= nil then if get_from_state(n) ~= nil then
vim.api.nvim_win_set_buf(0, state[n].buf_id) vim.api.nvim_win_set_buf(0, state[n].buf_id)
return return
end end