macos: setup undo responders at the AppDelegate level

This commit is contained in:
Mitchell Hashimoto
2025-06-05 21:43:41 -07:00
parent 6d32b01c64
commit f571519157
2 changed files with 25 additions and 1 deletions

View File

@@ -892,6 +892,14 @@ class AppDelegate: NSObject,
NSApplication.shared.arrangeInFront(sender)
}
@IBAction func undo(_ sender: Any?) {
undoManager.undo()
}
@IBAction func redo(_ sender: Any?) {
undoManager.redo()
}
private struct DerivedConfig {
let initialWindow: Bool
let shouldQuitAfterLastWindowClosed: Bool
@@ -981,6 +989,22 @@ extension AppDelegate: NSMenuItemValidation {
// terminal window (not quick terminal).
return NSApp.keyWindow is TerminalWindow
case #selector(undo(_:)):
if undoManager.canUndo {
item.title = "Undo \(undoManager.undoActionName)"
} else {
item.title = "Undo"
}
return undoManager.canUndo
case #selector(redo(_:)):
if undoManager.canRedo {
item.title = "Redo \(undoManager.redoActionName)"
} else {
item.title = "Redo"
}
return undoManager.canRedo
default:
return true
}

View File

@@ -228,7 +228,7 @@ class TerminalManager {
// Ensure any publishers we have are cancelled
w.closePublisher.cancel()
// If we remove a window, we reset the cascade point to the key window so that
// the next window cascade's from that one.
if let focusedWindow = NSApplication.shared.keyWindow {