From d076dcf093d74b259582d632f4c61fe6e87afc59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Jane=C5=BEi=C4=8D?= Date: Sat, 11 Oct 2025 20:35:04 +0200 Subject: [PATCH] fix: create new terminal if old isn't valid anymore --- plugin/geterm.lua | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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