Skip to content

Close window when closing the only remaining tab #2795

Open
stan-janssen wants to merge 1 commit into
elementary:mainfrom
stan-janssen:close-window-when-last-tab-is-closed
Open

Close window when closing the only remaining tab #2795
stan-janssen wants to merge 1 commit into
elementary:mainfrom
stan-janssen:close-window-when-last-tab-is-closed

Conversation

@stan-janssen
Copy link
Copy Markdown

@stan-janssen stan-janssen commented May 19, 2026

This closes the Files window when the only tab in that window is closed:

files-tab-closing.mp4

This makes the behavior consistent with other default apps like Terminal and Web, which also close their window when the last tab closes.

This also makes it possible to close a Files window using just the keyboard. Previously, one could only close tabs using ctrl + W, or close all windows using ctrl + Q, but not close just one window.

@stan-janssen stan-janssen changed the title Close window when closing last tab Close window when closing the only remaining tab May 19, 2026
@jeremypw
Copy link
Copy Markdown
Contributor

There has been some discussion as to the appropriate behaviour for a file manager when closing the last tab with different solutions proposed. See #327 and #1474. I do not personally see the utility of closing an app by closing a tab even though browsers and Terminal do. I understand the possible need for a way of closing just the current window with the keyboard but that is a different issue.

@danirabbit Would you like to see consistency between Files, Terminal, Code (and Browser)? If so what should be the common behaviour? Or is the correct behaviour dependent on the app?

@stan-janssen
Copy link
Copy Markdown
Author

Ah, I did not know that this was intended behavior, my bad.

I see that some excellent points were made in #327, so I can only add my intent here: My intent is: I'm done with these tabs, I don't want them restored at any point in the future, and I want them all to go away because I'm done with my file operation for now. Files is not really an application that I'm "doing work in", so to speak, so more often than not, if I close all my tabs, I don't want to "continue using Files". I press <Ctrl>+W the exact number of times that there are tabs open, and I expect the last one to also close the last window, just like Terminal and Web. Right now it feels like the app is fighting me, I'm startled that closing the last tab does note make the thing "go away", so to speak.

I think this is also what used to happen on Mac OS (it's been quite a few years since I've last used it), and I think it's also what happens in browsers on Windows.

The current re-opening-a-new-tab behavior has a bug by the way: pressing <Ctrl>W twice in succession with only one tab open reliable crashes the app (see attached gdb log of opening a window and quickly pressing <Ctrl>W twice). This might seem like a contrived thing, but in a window with a bunch of tabs open, if you press <Ctrl>W one time too many, it crashes the entire app and takes down all the other windows as well.

(Ironically, that was the exact scenario that danirabbit described here, except right now Files actually crashes when you mash <Ctrl>W one time too many, instead of just closing the last window)

files-crash.txt

If we don't want to change the behavior in Files, I can make a fix to this crashing bug. I'll follow the discussion here and see where we land. Thanks for taking the time anyway!

@jeremypw
Copy link
Copy Markdown
Contributor

jeremypw commented May 20, 2026

Although elementaryos tries to avoid unnecessary settings, if there are really two equally valid behaviours then adding another switch to the app menu is a possibility. Thanks for pointing out that crash - it certainly needs fixing.

@danirabbit
Copy link
Copy Markdown
Member

My personal opinion is that I don't usually love when one button does two different things, especially if one of those things is destructive.

We do however run into an issue where we don't have full control over the behavior of the web browser, so if our top priority is consistent behavior we might just have to follow that unless we can get upstream to carry a special behavior for us.

It sounds like what we might be hearing from folks though is that they're using the keyboard shortcut here and not the tab close button. So perhaps we should consider that the keyboard shortcut would close the window if there's only one tab but keep the current behavior for clicking the tab close button? Would that solve this issue for you @stan-janssen?

@jeremypw
Copy link
Copy Markdown
Contributor

jeremypw commented May 20, 2026

I agree that having two actions from the same button feels wrong, but the button itself always closes the tab - what happens afterwards may vary.

At the moment there are three different behaviours across (at least) four system apps - Files, Terminal, Code, Browser. I notice that Gnome Text Editor has yet another behaviour - that is to hide the tabbar when there is only one tab essentially preventing closing the last tab with the mouse (although the shortcut still works). If the tab is closed with the shortcut then it is replaced by a landing page, not a new document - mirroring Code. The same happens with Gnome File Manager (nautilus) except the window closes if the tab is closed with the shortcut - as is proposed here.

On reflection, I could live with closing the Files window on closing the last tab as, like Terminal, there is no sensible "landing page" for this type of app that I can think of. Then 3 out of 4 of the system apps with a tabbed view would behave the same way. Code can be regarded as different as an editor. Of course, the "no tabs" state cannot be restored - you will still end up with a home directory tab on restarting Files if it is the primary window that closes.

The home directory would still be only one click (bookmark) or shortcut (Alt+Home) away so nothing is really lost and we gain a shortcut for closing just the current window (indirectly)

@jeremypw
Copy link
Copy Markdown
Contributor

Will need to consider the text for the "Close Tab" option in the tab context menu (which is linked to the Ctrl+W shortcut). I guess this should change to "Close Tab and this Window" or something when there is only tab?

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.

3 participants