macos: search input starts the search up

pull/9709/head
Mitchell Hashimoto 2025-11-25 12:34:46 -08:00
parent 081d73d850
commit 5ee000f58f
No known key found for this signature in database
GPG Key ID: 523D5DC389D273BC
3 changed files with 17 additions and 9 deletions

View File

@ -391,7 +391,6 @@ extension Ghostty {
struct SurfaceSearchOverlay: View {
let surfaceView: SurfaceView
@Binding var searchState: SurfaceView.SearchState?
@State private var searchText: String = ""
@State private var corner: Corner = .topRight
@State private var dragOffset: CGSize = .zero
@State private var barSize: CGSize = .zero
@ -402,7 +401,10 @@ extension Ghostty {
var body: some View {
GeometryReader { geo in
HStack(spacing: 8) {
TextField("Search", text: $searchText)
TextField("Search", text: Binding(
get: { searchState?.needle ?? "" },
set: { searchState?.needle = $0 }
))
.textFieldStyle(.plain)
.frame(width: 180)
.padding(.horizontal, 8)
@ -436,9 +438,6 @@ extension Ghostty {
.cornerRadius(8)
.shadow(radius: 4)
.onAppear {
if let needle = searchState?.needle {
searchText = needle
}
isSearchFieldFocused = true
}
.onReceive(NotificationCenter.default.publisher(for: .ghosttySearchFocus)) { notification in

View File

@ -1,4 +1,5 @@
import AppKit
import Combine
import SwiftUI
import CoreText
import UserNotifications
@ -67,9 +68,14 @@ extension Ghostty {
// The current search state. When non-nil, the search overlay should be shown.
@Published var searchState: SearchState? = nil {
didSet {
// If the search state becomes nil, we need to make sure we're stopping
// the search internally.
if searchState == nil {
if let searchState {
searchNeedleCancellable = searchState.$needle.sink { [weak self] needle in
guard let surface = self?.surface else { return }
let action = "search:\(needle)"
ghostty_surface_binding_action(surface, action, UInt(action.count))
}
} else {
searchNeedleCancellable = nil
guard let surface = self.surface else { return }
let action = "search:"
ghostty_surface_binding_action(surface, action, UInt(action.count))
@ -77,6 +83,9 @@ extension Ghostty {
}
}
// Cancellable for search state needle changes
private var searchNeedleCancellable: AnyCancellable?
// The time this surface last became focused. This is a ContinuousClock.Instant
// on supported platforms.
@Published var focusInstant: ContinuousClock.Instant? = nil

View File

@ -4879,7 +4879,7 @@ pub fn performBindingAction(self: *Surface, action: input.Binding.Action) !bool
.start_search => if (self.search == null) {
// To save resources, we don't actually start a search here,
// we just notify teh apprt. The real thread will start when
// we just notify the apprt. The real thread will start when
// the first needles are set.
_ = try self.rt_app.performAction(
.{ .surface = self },