Skip to content

fix: tabs close - #10

Merged
sand4rt merged 1 commit into
mainfrom
fix-tab-close
Apr 17, 2026
Merged

sand4rt merged 1 commit into
mainfrom
fix-tab-close

Conversation

@sand4rt

@sand4rt sand4rt commented Apr 17, 2026

Copy link
Copy Markdown
Owner

No description provided.

Copilot AI review requested due to automatic review settings April 17, 2026 09:55
@sand4rt
sand4rt merged commit 9e9a830 into main Apr 17, 2026
3 checks passed
@sand4rt
sand4rt deleted the fix-tab-close branch April 17, 2026 09:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 :tabnew then :q behavior.

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.

Comment thread lua/zen/init.lua
Comment on lines 318 to 322
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

Copilot AI Apr 17, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()).

Copilot uses AI. Check for mistakes.
Comment thread tests/test_tabs.lua
Comment on lines +27 to +39
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

Copilot AI Apr 17, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants