From bc7db466960fa33903aa0d5a69808f869c447708 Mon Sep 17 00:00:00 2001 From: Immanuel Haffner Date: Tue, 10 Mar 2026 10:52:24 +0100 Subject: [PATCH] fix(ui): guard close_tab against nil or invalid window `close_tab()` calls `nvim_win_close(term.window)` without checking if `term.window` is valid, unlike `close_split()` which already has this guard. This causes "Expected Lua number" errors when the window reference is `nil` at the time of closing (e.g. when `on_exit` callbacks clear it before the close flow completes). Add an early-return guard matching the pattern used by `close_split()`. --- lua/toggleterm/ui.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/lua/toggleterm/ui.lua b/lua/toggleterm/ui.lua index d76978fa..f56ccde3 100644 --- a/lua/toggleterm/ui.lua +++ b/lua/toggleterm/ui.lua @@ -345,6 +345,7 @@ end ---@param term Terminal local function close_tab(term) + if not term.window or not api.nvim_win_is_valid(term.window) then return end if #vim.api.nvim_list_tabpages() == 1 then return utils.notify("You cannot close the last tab! This will exit neovim", "error") end