From 97c5a21abae800c7cb3e0af3610aa4eb73da47ed Mon Sep 17 00:00:00 2001 From: Lukas <134181853+bo2themax@users.noreply.github.com> Date: Mon, 27 Apr 2026 18:56:22 +0200 Subject: [PATCH] macOS: fix ending search in menu bar does focus on surface --- macos/Sources/Ghostty/Ghostty.App.swift | 15 ++++++++------- .../Ghostty/Surface View/OSSurfaceView.swift | 5 +++++ .../Ghostty/Surface View/SurfaceView.swift | 5 +---- .../Ghostty/Surface View/SurfaceView_AppKit.swift | 5 +++++ 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/macos/Sources/Ghostty/Ghostty.App.swift b/macos/Sources/Ghostty/Ghostty.App.swift index 8dbca3b57..018122760 100644 --- a/macos/Sources/Ghostty/Ghostty.App.swift +++ b/macos/Sources/Ghostty/Ghostty.App.swift @@ -645,7 +645,7 @@ extension Ghostty { startSearch(app, target: target, v: action.action.start_search) case GHOSTTY_ACTION_END_SEARCH: - endSearch(app, target: target) + return endSearch(app, target: target) case GHOSTTY_ACTION_SEARCH_TOTAL: searchTotal(app, target: target, v: action.action.search_total) @@ -2078,22 +2078,23 @@ extension Ghostty { private static func endSearch( _ app: ghostty_app_t, - target: ghostty_target_s) { + target: ghostty_target_s) -> Bool { switch target.tag { case GHOSTTY_TARGET_APP: Ghostty.logger.warning("end_search does nothing with an app target") - return + return false case GHOSTTY_TARGET_SURFACE: - guard let surface = target.target.surface else { return } - guard let surfaceView = self.surfaceView(from: surface) else { return } + guard let surface = target.target.surface else { return false } + guard let surfaceView = self.surfaceView(from: surface) else { return false } DispatchQueue.main.async { - surfaceView.searchState = nil + surfaceView.endSearch() } - + return true default: assertionFailure() + return false } } diff --git a/macos/Sources/Ghostty/Surface View/OSSurfaceView.swift b/macos/Sources/Ghostty/Surface View/OSSurfaceView.swift index 8553e563f..d07a2e0c8 100644 --- a/macos/Sources/Ghostty/Surface View/OSSurfaceView.swift +++ b/macos/Sources/Ghostty/Surface View/OSSurfaceView.swift @@ -99,6 +99,11 @@ extension Ghostty { self.childExitedMessage = message } + @MainActor + func endSearch() { + searchState = nil + } + // MARK: - Placeholders func focusDidChange(_ focused: Bool) {} diff --git a/macos/Sources/Ghostty/Surface View/SurfaceView.swift b/macos/Sources/Ghostty/Surface View/SurfaceView.swift index ec6f61197..d9fe83cd6 100644 --- a/macos/Sources/Ghostty/Surface View/SurfaceView.swift +++ b/macos/Sources/Ghostty/Surface View/SurfaceView.swift @@ -164,10 +164,7 @@ extension Ghostty { surfaceView: surfaceView, searchState: searchState, onClose: { -#if canImport(AppKit) - Ghostty.moveFocus(to: surfaceView) -#endif - surfaceView.searchState = nil + surfaceView.endSearch() } ) } diff --git a/macos/Sources/Ghostty/Surface View/SurfaceView_AppKit.swift b/macos/Sources/Ghostty/Surface View/SurfaceView_AppKit.swift index 1c66188f4..66c0de10f 100644 --- a/macos/Sources/Ghostty/Surface View/SurfaceView_AppKit.swift +++ b/macos/Sources/Ghostty/Surface View/SurfaceView_AppKit.swift @@ -389,6 +389,11 @@ extension Ghostty { progressReportTimer?.invalidate() } + override func endSearch() { + Ghostty.moveFocus(to: self) + super.endSearch() + } + override func focusDidChange(_ focused: Bool) { guard let surface = self.surface else { return } guard self.focused != focused else { return }