mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-04-14 19:45:49 +00:00
macOS: move searchState to OSSurfaceView
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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? {
|
||||
|
||||
Reference in New Issue
Block a user