macOS: fix ending search in menu bar does focus on surface

This commit is contained in:
Lukas
2026-04-27 18:56:22 +02:00
parent 1df7a5d3f3
commit 97c5a21aba
4 changed files with 19 additions and 11 deletions

View File

@@ -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
}
}

View File

@@ -99,6 +99,11 @@ extension Ghostty {
self.childExitedMessage = message
}
@MainActor
func endSearch() {
searchState = nil
}
// MARK: - Placeholders
func focusDidChange(_ focused: Bool) {}

View File

@@ -164,10 +164,7 @@ extension Ghostty {
surfaceView: surfaceView,
searchState: searchState,
onClose: {
#if canImport(AppKit)
Ghostty.moveFocus(to: surfaceView)
#endif
surfaceView.searchState = nil
surfaceView.endSearch()
}
)
}

View File

@@ -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 }