diff --git a/macos/Sources/Ghostty/Surface View/OSSurfaceView.swift b/macos/Sources/Ghostty/Surface View/OSSurfaceView.swift index e9f49a769..de71dc997 100644 --- a/macos/Sources/Ghostty/Surface View/OSSurfaceView.swift +++ b/macos/Sources/Ghostty/Surface View/OSSurfaceView.swift @@ -34,6 +34,9 @@ extension Ghostty { // The currently active key tables. Empty if no tables are active. @Published var keyTables: [String] = [] + // The current search state. When non-nil, the search overlay should be shown. + @Published var searchState: SearchState? + // The time this surface last became focused. This is a ContinuousClock.Instant // on supported platforms. @Published var focusInstant: ContinuousClock.Instant? @@ -91,3 +94,40 @@ extension Ghostty { } } +// MARK: Search State + +extension Ghostty.OSSurfaceView { + class SearchState: ObservableObject { + @Published var needle: String = "" + @Published var selected: UInt? + @Published var total: UInt? + + init(from startSearch: Ghostty.Action.StartSearch) { + self.needle = startSearch.needle ?? "" + } + } + + func navigateSearchToNext() -> Bool { + guard let surface = self.surface else { return false } + let action = "navigate_search:next" + if !ghostty_surface_binding_action(surface, action, UInt(action.lengthOfBytes(using: .utf8))) { +#if canImport(AppKit) + AppDelegate.logger.warning("action failed action=\(action)") +#endif + return false + } + return true + } + + func navigateSearchToPrevious() -> Bool { + guard let surface = self.surface else { return false } + let action = "navigate_search:previous" + if !ghostty_surface_binding_action(surface, action, UInt(action.lengthOfBytes(using: .utf8))) { +#if canImport(AppKit) + AppDelegate.logger.warning("action failed action=\(action)") +#endif + return false + } + return true + } +} diff --git a/macos/Sources/Ghostty/Surface View/SurfaceView.swift b/macos/Sources/Ghostty/Surface View/SurfaceView.swift index a6ddf4219..2c393d7c5 100644 --- a/macos/Sources/Ghostty/Surface View/SurfaceView.swift +++ b/macos/Sources/Ghostty/Surface View/SurfaceView.swift @@ -1267,41 +1267,3 @@ extension FocusedValues { typealias Value = OSSize } } - -// MARK: Search State - -extension Ghostty.SurfaceView { - class SearchState: ObservableObject { - @Published var needle: String = "" - @Published var selected: UInt? - @Published var total: UInt? - - init(from startSearch: Ghostty.Action.StartSearch) { - self.needle = startSearch.needle ?? "" - } - } - - func navigateSearchToNext() -> Bool { - guard let surface = self.surface else { return false } - let action = "navigate_search:next" - if !ghostty_surface_binding_action(surface, action, UInt(action.lengthOfBytes(using: .utf8))) { -#if canImport(AppKit) - AppDelegate.logger.warning("action failed action=\(action)") -#endif - return false - } - return true - } - - func navigateSearchToPrevious() -> Bool { - guard let surface = self.surface else { return false } - let action = "navigate_search:previous" - if !ghostty_surface_binding_action(surface, action, UInt(action.lengthOfBytes(using: .utf8))) { -#if canImport(AppKit) - AppDelegate.logger.warning("action failed action=\(action)") -#endif - return false - } - return true - } -} diff --git a/macos/Sources/Ghostty/Surface View/SurfaceView_AppKit.swift b/macos/Sources/Ghostty/Surface View/SurfaceView_AppKit.swift index 726892e18..db8f02494 100644 --- a/macos/Sources/Ghostty/Surface View/SurfaceView_AppKit.swift +++ b/macos/Sources/Ghostty/Surface View/SurfaceView_AppKit.swift @@ -40,7 +40,7 @@ extension Ghostty { @Published var keySequence: [KeyboardShortcut] = [] // The current search state. When non-nil, the search overlay should be shown. - @Published var searchState: SearchState? { + override var searchState: SearchState? { didSet { if let searchState { // I'm not a Combine expert so if there is a better way to do this I'm diff --git a/macos/Sources/Ghostty/Surface View/SurfaceView_UIKit.swift b/macos/Sources/Ghostty/Surface View/SurfaceView_UIKit.swift index 3b5034a0e..a4a643bb1 100644 --- a/macos/Sources/Ghostty/Surface View/SurfaceView_UIKit.swift +++ b/macos/Sources/Ghostty/Surface View/SurfaceView_UIKit.swift @@ -11,9 +11,6 @@ extension Ghostty { /// True when the bell is active. This is set inactive on focus or event. @Published var bell: Bool = false - // The current search state. When non-nil, the search overlay should be shown. - @Published var searchState: SearchState? - private(set) var _surface: ghostty_surface_t? override var surface: ghostty_surface_t? {