mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-21 19:26:09 +03:00

This PR implements the ability to undo/redo new and closed windows, tabs, and splits. ## Demo https://github.com/user-attachments/assets/98601810-71b8-4adb-bfa4-bdfaa2526dc6 ## Details ### Undo Timeout Running terminal sessions _remain running_ for a configurable period of time after close, during which time they're undoable. This is similar to "email unsend" (since email in the traditional sense can't be unsent, clients simply hold onto it for a period of time before sending). This behavior is not unique to Ghostty. The first and only place I've seen it is in iTerm2. And iTerm2 behaves similarly, although details of our behavior and our implementation vary greatly. The configurable period of time is done via the `undo-timeout` configuration. The default value is 5 seconds. This feels reasonable to be and is grounded in being the default for iTerm2 as well, so it's probably a safe choice. Undo can be disabled by setting `undo-timeout = 0`. ### Future The actions that can be potentially undone/redone can be easily expanded in the future. Some thoughts on things that make sense to me: - Any sort of split resizing, including equalization - Moving tabs or splits #### What about Linux? I'd love to support this on Linux. I don't think any other terminal on Linux has this kind of feature (definitely might be wrong, but I've never seen it and I've looked at a lot of terminal emulators 😄 ). But there's some work to be done to get there. ## TODO for the Draft PR This is still a draft. There are some items remaining (list will update as I go): - [x] Undoing a closed window is sometimes buggy still and I'm not sure why, I have to dig into this. - [x] New window should be undoable - [x] New tab should be undoable - [x] Close All Windows should be undoable - [x] I think I have to get rid of TerminalManager. Undone windows won't be in TerminalManager's list of controllers and I think that's going to break a lot of things. - [x] I haven't tested this with QuickTerminal at all. I expect bugs there but I want undo to work with splits there. - [x] Close window with the red traffic light button doesn't trigger undo - [x] Closing window with multiple tabs undoes them as separate windows