Skip to content

Undo close tab (Ctrl+Shift+T) reopens the last closed file tab where it was, with its undo - #580

Open
a-team-app[bot] wants to merge 5 commits into
mainfrom
milestone-343-undo-close-tab
Open

a-team-app[bot] wants to merge 5 commits into
mainfrom
milestone-343-undo-close-tab

Conversation

@a-team-app

@a-team-app a-team-app Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Ctrl+Shift+T (also uct, and File › Undo close tab after Close all tabs) reopens the file tab you closed most recently. It comes back in the same group and slot in the tab strip as the active tab, with the cursor and scroll where they were. Ctrl+Z and redo pick up where they left off, as long as the file on disk still holds what the tab had when it closed. Press it again to bring back the next one. After Close other tabs or Close all tabs, repeated presses bring the tabs back one at a time, in their original order.

Closes #578

Notes

  • The tab close button criterion: TG's Tabs draws no close button on a tab, so TuiCode has none. Every way a file tab closes goes through EditorGroup.Close, and that is where tabs are remembered, so a close button added later would count with no extra work.
  • A tab from a second group that has gone (e.g. after Close all tabs with a split) reopens at the end of the first group. Its old index belonged to the other group's strip, so it means nothing in the first.
  • The F1 Tabs row, like every F1 row, appears only while the command is enabled, so it shows once something has been closed. With nothing to reopen, the item is dimmed in the menu and left out of the palette.
  • Up to 20 closed tabs are kept per session. Switching folders or quitting forgets them.

a-team try tuicode 580

Closing a tab by mistake meant finding the file again and losing its
undo history. Each file tab that closes is now remembered (up to 20 per
session) with its group, strip index, cursor and undo steps, and
Ctrl+Shift+T / uct / File > Undo close tab brings the newest back.

The strip index is taken as each tab goes, so after Close other or
Close all tabs repeated presses rebuild the strip in order. Undo is
restored only when the reopened file's lines are exactly those the
steps were recorded against, VS Code's rule, so a file changed on disk
or closed dirty with Don't save reopens with fresh history. Files open
again or deleted are skipped; a folder switch clears the list.

Closes #578

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
a-team-app Bot and others added 3 commits October 20, 2026 20:20
#581 and #582 merged in parallel: #581's test still looked for ConfirmView,
which #582 removed, so main no longer builds its tests.

Closes #578

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@a-team-app

a-team-app Bot commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

CI broke because main is red, not because of this PR. #581's UnsavedEditsHostTests still used ConfirmView, which #582 removed. I merged main in and switched that test to ConfirmDialogs.Choose(..., "Don't save") (5a0138d). Merging this PR fixes main as well.

A_renamed_file_takes_its_copy_with_it counted the recovery folder while
the next session's background write was still mid-rename, so it
occasionally saw a leftover .tmp file. Recovering_takes_over_the_copy
already waits; this test now does too.

Closes #578

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@a-team-app

a-team-app Bot commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

CI failed on UnsavedEditsTests.A_renamed_file_takes_its_copy_with_it, which came from #581 and not from this change. The test counted recovery copies before the next session's background write had finished, so it sometimes saw a leftover .tmp. Fixed in 1ea30a7 by waiting for that write, as Recovering_takes_over_the_copy already does.

This branch has not been deployed

No deployments
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.

Undo close tab (Ctrl+Shift+T) reopens the last closed file tab where it was, with its undo

0 participants