macOS: move searchState to OSSurfaceView

This commit is contained in:
Lukas
2026-04-12 12:24:36 +02:00
parent a541e23120
commit 90ea604a7c
4 changed files with 41 additions and 42 deletions

View File

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

View File

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

View File

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

View File

@@ -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? {