macos: search input starts the search up
parent
081d73d850
commit
5ee000f58f
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import AppKit
|
||||
import Combine
|
||||
import SwiftUI
|
||||
import CoreText
|
||||
import UserNotifications
|
||||
|
|
@ -67,15 +68,23 @@ 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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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.
|
||||
|
|
|
|||
|
|
@ -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 },
|
||||
|
|
|
|||
Loading…
Reference in New Issue