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!
This commit is contained in:
Sean Dewar
2026-03-15 10:18:31 +00:00
parent e80d19142b
commit cd4c98fded
6 changed files with 258 additions and 261 deletions

View File

@@ -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.