Repository navigation
fix: tabs close - #10
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes tab-closing behavior when quitting the last “main” (non-zen / non-integration) window inside a tab by ensuring the QuitPre logic only counts windows in the current tabpage.
Changes:
- Scope the QuitPre “editable window” count to the current tabpage (
nvim_tabpage_list_wins(0)), enabling proper cleanup so the tab can close. - Add a regression test covering
:tabnewthen:qbehavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
lua/zen/init.lua |
Updates QuitPre window enumeration to be tab-local, addressing tabs not closing due to cross-tab window counting. |
tests/test_tabs.lua |
Adds a test case to validate tab closing behavior when quitting the last main window in a new tab. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| local editable_count = 0 | ||
| for _, win in ipairs(vim.api.nvim_list_wins()) do | ||
| for _, win in ipairs(vim.api.nvim_tabpage_list_wins(0)) do | ||
| if not is_popup_window(win) then | ||
| local buf = vim.api.nvim_win_get_buf(win) | ||
| if not is_buff_integration(buf) then |
There was a problem hiding this comment.
In the QuitPre handler, switching editable_count to only consider the current tabpage means this block will now run even when other tabs are open. However, the subsequent close(integration.filetype) uses vim.api.nvim_list_wins() (global) and can therefore close integration windows in other tabpages (e.g., a fugitive/trouble window open in another tab) when quitting the last main window in the current tab. Consider scoping the integration-window closes to the current tabpage here (e.g. iterate nvim_tabpage_list_wins(0) when closing, or add a tabpage-scoped variant of close()).
| T["close tab on last main quit"] = function() | ||
| child.cmd("tabnew") | ||
| child.cmd("q") | ||
|
|
||
| Helpers.expect.layout(child, { | ||
| type = "row", | ||
| children = { | ||
| { type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 50 }, | ||
| { type = "leaf", filetype = "", buftype = "", width = 146, height = 50 }, | ||
| { type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 50 }, | ||
| }, | ||
| }) | ||
| end |
There was a problem hiding this comment.
This test is named "close tab on last main quit", but it only asserts the resulting window layout. To make the intent explicit (and reduce the chance of a false-positive if the layout happens to match without the tab being closed), consider also asserting the tab count or current tab number after child.cmd("q") (e.g. tabpagenr('$') == 1, or that you returned to the original tab).
No description provided.