// `/search` — the pill on top, the answer underneath, on the paper ground. // // The answer itself is `SearchResults` (`Screens/Search/SearchResults.swift`), // which Home draws too, under its own title (design 2026-09-13 §4.4). This // screen is what is LEFT once the answer is shared: the page ground and the // pill at the top, where the redesign's picture 29 puts it. Everything about // what a search shows — recents at rest, grouped hits as you type, a place // swapping and a record pushing — lives in the shared view and `SearchModel`, // so the page and Home cannot drift. // // Taps persist and a drag dismisses the keyboard — that is // `.scrollDismissesKeyboard(.immediately)` on the results, where the scroller // is. import CottonKit import SwiftUI public struct SearchScreen: View { private let model: SearchModel /// The pill's close. On this screen the search IS the screen, so leaving /// is the only thing close can mean. @Environment(\.dismiss) private var dismiss @Environment(\.theme) private var theme /// The gallery draws a specimen that must not raise a keyboard nobody asked /// for — the same argument `SearchPill` already takes. private let takesFocus: Bool @FocusState private var isFocused: Bool public init( model: SearchModel, takesFocus: Bool = true ) { self.model = model self.takesFocus = takesFocus } private var field: Binding { Binding(get: { model.query }, set: { model.type($0) }) } public var body: some View { ZStack(alignment: .top) { PageGroundFill().ignoresSafeArea() VStack(spacing: 0) { // THE app search field, on top: it focuses itself on appear, // so the page opens asking. HStack(spacing: 10) { SearchField(text: field, placeholder: SearchWords.scope, isFocused: $isFocused) .accessibilityIdentifier("cap-search") Button { SearchGrammar.close(clear: { model.type("") }, then: { dismiss() }) } label: { Text(ShellLines.line("search", "close")) .font(CottonFonts.type(theme.scale.titleSize)) .underline() .foregroundStyle(CottonColors.ink) .padding(.vertical, 12) } .buttonStyle(.plain) .accessibilityIdentifier("cap-search-close") } .padding(.horizontal, ChromeKnobs.chromeSettingsMargin) .padding(.top, 6) .accessibilityElement(children: .contain) .accessibilityIdentifier("search-pill-row") // An empty field is the page at rest — the searches made // before, else the one line saying what a search reaches // (`SearchResults`). Never a list of every table: a table is // found by typing its name, which answers it as a place. SearchResults(model: model) .padding(.top, 10) } } .cottonPageGround(.groundMuted) .cottonPageTexture(.plaster) .accessibilityElement(children: .contain) .accessibilityIdentifier("global-search") .onAppear { if takesFocus { isFocused = true } } } }