macos: fix up command palette, focusing

pull/7523/head
Mitchell Hashimoto 2025-06-04 09:42:12 -07:00
parent 7dcfebcd5d
commit aef61661a0
No known key found for this signature in database
GPG Key ID: 523D5DC389D273BC
4 changed files with 21 additions and 8 deletions

View File

@ -314,7 +314,6 @@
A5A2A3CB2D444AB80033CF96 /* NSApplication+Extension.swift */,
A54B0CEA2D0CFB4A00CBEFF8 /* NSImage+Extension.swift */,
A52FFF5C2CAB4D05000C6A5B /* NSScreen+Extension.swift */,
C1F26EA62B738B9900404083 /* NSView+Extension.swift */,
AEE8B3442B9AA39600260C5E /* NSPasteboard+Extension.swift */,
A5874D9C2DAD785F00E83852 /* NSWindow+Extension.swift */,
A5985CD62C320C4500C57AD3 /* String+Extension.swift */,
@ -449,6 +448,7 @@
isa = PBXGroup;
children = (
A586366A2DF0A98900E04A10 /* Array+Extension.swift */,
C1F26EA62B738B9900404083 /* NSView+Extension.swift */,
);
path = Extensions;
sourceTree = "<group>";

View File

@ -295,14 +295,14 @@ class BaseTerminalController: NSWindowController,
@objc private func ghosttyCommandPaletteDidToggle(_ notification: Notification) {
guard let surfaceView = notification.object as? Ghostty.SurfaceView else { return }
guard surfaceTree?.contains(view: surfaceView) ?? false else { return }
guard surfaceTree2.contains(surfaceView) else { return }
toggleCommandPalette(nil)
}
@objc private func ghosttyMaximizeDidToggle(_ notification: Notification) {
guard let window else { return }
guard let surfaceView = notification.object as? Ghostty.SurfaceView else { return }
guard surfaceTree?.contains(view: surfaceView) ?? false else { return }
guard surfaceTree2.contains(surfaceView) else { return }
window.zoom(nil)
}
@ -468,7 +468,7 @@ class BaseTerminalController: NSWindowController,
// want to care if the surface is in the tree so we don't listen to titles of
// closed surfaces.
if let titleSurface = focusedSurface ?? lastFocusedSurface,
surfaceTree?.contains(view: titleSurface) ?? false {
surfaceTree2.contains(titleSurface) {
// If we have a surface, we want to listen for title changes.
titleSurface.$title
.sink { [weak self] in self?.titleDidChange(to: $0) }

View File

@ -159,7 +159,7 @@ class TerminalController: BaseTerminalController {
// This is a surface-level config update. If we have the surface, we
// update our appearance based on it.
guard let surfaceView = notification.object as? Ghostty.SurfaceView else { return }
guard surfaceTree?.contains(view: surfaceView) ?? false else { return }
guard surfaceTree2.contains(surfaceView) else { return }
// We can't use surfaceView.derivedConfig because it may not be updated
// yet since it also responds to notifications.
@ -815,19 +815,19 @@ class TerminalController: BaseTerminalController {
@objc private func onCloseTab(notification: SwiftUI.Notification) {
guard let target = notification.object as? Ghostty.SurfaceView else { return }
guard surfaceTree?.contains(view: target) ?? false else { return }
guard surfaceTree2.contains(target) else { return }
closeTab(self)
}
@objc private func onCloseWindow(notification: SwiftUI.Notification) {
guard let target = notification.object as? Ghostty.SurfaceView else { return }
guard surfaceTree?.contains(view: target) ?? false else { return }
guard surfaceTree2.contains(target) else { return }
closeWindow(self)
}
@objc private func onResetWindowSize(notification: SwiftUI.Notification) {
guard let target = notification.object as? Ghostty.SurfaceView else { return }
guard surfaceTree?.contains(view: target) ?? false else { return }
guard surfaceTree2.contains(target) else { return }
returnToDefaultSize(nil)
}

View File

@ -1,6 +1,19 @@
import AppKit
extension NSView {
/// Returns true if this view is currently in the responder chain
var isInResponderChain: Bool {
var responder = window?.firstResponder
while let currentResponder = responder {
if currentResponder === self {
return true
}
responder = currentResponder.nextResponder
}
return false
}
/// Recursively finds and returns the first descendant view that has the given class name.
func firstDescendant(withClassName name: String) -> NSView? {
for subview in subviews {