diff --git a/plugin/geterm.lua b/plugin/geterm.lua index c9195f2..0eaf2b8 100644 --- a/plugin/geterm.lua +++ b/plugin/geterm.lua @@ -5,9 +5,20 @@ ---@type table 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 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) return end