From cd4c98fded9490378bdb33966d14773242941905 Mon Sep 17 00:00:00 2001 From: Sean Dewar <6256228+seandewar@users.noreply.github.com> Date: Sun, 15 Mar 2026 10:18:31 +0000 Subject: fix: nvim_open_tabpage cleanup, fixes, more tests - Cleanup, remove redundant comments, add more tests. - Enhance win_new_tabpage rather than create a new function for !enter, and use a different approach that minimizes side-effects. Return the tabpage_T * and first win_T * it allocated. - Disallow during textlock, like other APIs that open windows. - Remove existing win_alloc_firstwin error handling from win_new_tabpage; it's not needed, and looks incorrect. (enter_tabpage is called for curtab, which is not the old tabpage! Plus newtp is not freed) - Fix checks after creating the tabpage: - Don't fail if buf wasn't set successfully; the tab page may still be valid regardless. Set buffer like nvim_open_win, possibly blocking Enter/Leave events. (except BufWinEnter) - tp_curwin may not be the initial window opened by win_new_tabpage. Use the win_T * it returns instead, which is the real first window it allocated, regardless of autocmd shenanigans. - Properly check whether tab page was freed; it may have also been freed before win_set_buf. Plus, it may not be safe to read its handle! --- runtime/lua/vim/_meta/api.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'runtime/lua/vim/_meta/api.lua') diff --git a/runtime/lua/vim/_meta/api.lua b/runtime/lua/vim/_meta/api.lua index 6be9305d48..b49a547d63 100644 --- a/runtime/lua/vim/_meta/api.lua +++ b/runtime/lua/vim/_meta/api.lua @@ -1673,7 +1673,7 @@ function vim.api.nvim_load_context(dict) end --- @return any function vim.api.nvim_notify(msg, log_level, opts) end ---- Opens a new tabpage +--- Opens a new tabpage. --- --- @param buffer integer Buffer to open in the first window of the new tabpage. --- Use 0 for current buffer. -- cgit