Compare commits

..
Author SHA1 Message Date
buzzert 8e9c111949 fix(ios): select Quick Question draft after focus
TestFlight / Build and upload (push) Successful in 1m52s
2026-11-17 22:27:23 -08:00
buzzert 7c15357108 fix(ios): restore Quick Question composer behavior
TestFlight / Build and upload (push) Successful in 1m53s
2026-11-17 21:44:44 -08:00
buzzert ea6ee8cc64 feat(ios): submit Quick Question on Return
TestFlight / Build and upload (push) Successful in 1m57s
2026-11-17 20:53:18 -08:00
buzzert 557775af45 fix(ios): align Quick Question composer and selection
TestFlight / Build and upload (push) Successful in 2m12s
2026-11-17 19:55:02 -08:00
2 changed files with 66 additions and 143 deletions
@@ -1,7 +1,6 @@
import MarkdownUI
import Observation
import SwiftUI
import UIKit
struct SybilQuickQuestionView: View {
@Bindable var viewModel: SybilViewModel
@@ -9,6 +8,8 @@ struct SybilQuickQuestionView: View {
@Environment(\.dismiss) private var dismiss
@FocusState private var promptFocused: Bool
@State private var promptSelection: TextSelection?
@State private var selectionAppliedForFocusRequest: Int?
private var hasAnswerContent: Bool {
!viewModel.quickQuestionMessages.isEmpty || viewModel.quickQuestionError != nil
@@ -36,7 +37,15 @@ struct SybilQuickQuestionView: View {
guard !Task.isCancelled else {
return
}
promptFocused = true
if promptFocused {
selectPromptForCurrentFocusRequest()
} else {
promptFocused = true
}
}
.onChange(of: promptFocused) { _, isFocused in
guard isFocused else { return }
selectPromptForCurrentFocusRequest()
}
}
@@ -93,29 +102,17 @@ struct SybilQuickQuestionView: View {
private var composer: some View {
VStack(alignment: .leading, spacing: 10) {
HStack(alignment: .bottom, spacing: 10) {
QuickQuestionTextField(
SybilPromptField(
placeholder: "Ask anything...",
text: Binding(
get: { viewModel.quickQuestionPrompt },
set: { viewModel.updateQuickQuestionPrompt($0) }
),
focused: Binding(
get: { promptFocused },
set: { promptFocused = $0 }
),
focusRequest: focusRequest,
focused: $promptFocused,
selection: $promptSelection,
axis: .horizontal,
submit: submitQuestion
)
.focused($promptFocused)
.font(.sybil(.body))
.padding(.horizontal, 12)
.padding(.vertical, 10)
.frame(maxWidth: .infinity, minHeight: 40, alignment: .leading)
.background(
RoundedRectangle(cornerRadius: 12)
.fill(SybilTheme.composerGradient)
.opacity(0.98)
)
SybilPromptSendButton(canSend: viewModel.canSendQuickQuestion, submit: submitQuestion)
.accessibilityLabel("Ask quick question")
@@ -216,112 +213,12 @@ struct SybilQuickQuestionView: View {
promptFocused = false
_ = viewModel.sendQuickQuestion()
}
}
private final class QuickQuestionNativeTextField: UITextField {
var wantsFirstResponder = false {
didSet {
updateFirstResponder()
}
}
override func didMoveToWindow() {
super.didMoveToWindow()
updateFirstResponder()
}
private func updateFirstResponder() {
guard window != nil else {
return
}
if wantsFirstResponder && !isFirstResponder {
becomeFirstResponder()
} else if !wantsFirstResponder && isFirstResponder {
resignFirstResponder()
}
}
}
private struct QuickQuestionTextField: UIViewRepresentable {
var placeholder: String
@Binding var text: String
@Binding var focused: Bool
var focusRequest: Int
var submit: () -> Void
func makeUIView(context: Context) -> QuickQuestionNativeTextField {
SybilFontRegistry.registerIfNeeded()
let textField = QuickQuestionNativeTextField()
textField.delegate = context.coordinator
textField.addTarget(context.coordinator, action: #selector(Coordinator.textDidChange(_:)), for: .editingChanged)
textField.placeholder = placeholder
let baseFont = UIFont(name: "Inter", size: 17) ?? UIFont.systemFont(ofSize: 17)
textField.font = UIFontMetrics(forTextStyle: .body).scaledFont(for: baseFont)
textField.adjustsFontForContentSizeCategory = true
textField.textColor = UIColor(SybilTheme.text)
textField.backgroundColor = .clear
textField.borderStyle = .none
textField.autocapitalizationType = .sentences
textField.autocorrectionType = .yes
textField.returnKeyType = .send
textField.keyboardAppearance = .dark
textField.accessibilityIdentifier = "quick-question-prompt"
textField.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
textField.setContentHuggingPriority(.defaultLow, for: .horizontal)
return textField
}
func updateUIView(_ textField: QuickQuestionNativeTextField, context: Context) {
context.coordinator.parent = self
if textField.text != text {
textField.text = text
}
textField.wantsFirstResponder = focused
}
func makeCoordinator() -> Coordinator {
Coordinator(parent: self)
}
@MainActor
final class Coordinator: NSObject, UITextFieldDelegate {
var parent: QuickQuestionTextField
private var lastSelectedFocusRequest: Int?
init(parent: QuickQuestionTextField) {
self.parent = parent
}
@objc func textDidChange(_ textField: UITextField) {
parent.text = textField.text ?? ""
}
func textFieldDidBeginEditing(_ textField: UITextField) {
parent.focused = true
guard lastSelectedFocusRequest != parent.focusRequest else {
return
}
lastSelectedFocusRequest = parent.focusRequest
guard let text = textField.text, !text.isEmpty,
let range = textField.textRange(
from: textField.beginningOfDocument,
to: textField.endOfDocument
)
else {
return
}
textField.selectedTextRange = range
}
func textFieldDidEndEditing(_ textField: UITextField) {
parent.focused = false
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
parent.submit()
return false
}
private func selectPromptForCurrentFocusRequest() {
guard selectionAppliedForFocusRequest != focusRequest else { return }
let prompt = viewModel.quickQuestionPrompt
promptSelection = TextSelection(range: prompt.startIndex..<prompt.endIndex)
selectionAppliedForFocusRequest = focusRequest
}
}
@@ -1,6 +1,6 @@
import XCTest
/// Uses the repository's 127.0.0.1 contract fixture and the real iOS home-screen shortcut.
/// Exercises Quick Question through its real home-screen action and shared SwiftUI field.
@MainActor
final class QuickQuestionSelectionUITests: XCTestCase {
private let app = XCUIApplication()
@@ -19,33 +19,72 @@ final class QuickQuestionSelectionUITests: XCTestCase {
app.terminate()
}
func testPrefilledDraftIsSelectedOnReopenAndTypingReplacesIt() async throws {
func testQuickQuestionKeepsKeyboardVisibleAcrossSeparateKeypressesAndStaysCompact() {
app.launch()
openQuickQuestionFromHomeScreen()
let prompt = app.textFields["quick-question-prompt"]
let prompt = quickQuestionPrompt()
XCTAssertTrue(prompt.waitForExistence(timeout: 10))
XCTAssertTrue(app.keyboards.firstMatch.waitForExistence(timeout: 10))
XCTAssertLessThan(prompt.frame.height, 80, "Quick Question should retain its original compact single-line field.")
prompt.typeText("a")
XCTAssertTrue(app.keyboards.firstMatch.exists, "Keyboard should remain visible after the first keypress.")
prompt.typeText("b")
XCTAssertTrue(app.keyboards.firstMatch.exists, "Keyboard should remain visible after the second keypress.")
prompt.typeText("c")
XCTAssertTrue(app.keyboards.firstMatch.exists, "Keyboard should remain visible after the third keypress.")
XCTAssertEqual(prompt.value as? String, "abc")
}
func testQuickQuestionDismissalAndReappearanceSelectsRetainedDraftForReplacement() {
app.launch()
openQuickQuestionFromHomeScreen()
let prompt = quickQuestionPrompt()
XCTAssertTrue(prompt.waitForExistence(timeout: 10))
XCTAssertTrue(app.keyboards.firstMatch.waitForExistence(timeout: 10))
prompt.typeText("retained draft")
XCTAssertEqual(prompt.value as? String, "retained draft")
dismissQuickQuestion(prompt)
dismissQuickQuestion()
let dismissed = XCTNSPredicateExpectation(predicate: NSPredicate(format: "exists == false"), object: prompt)
wait(for: [dismissed], timeout: 5)
// Reopen through the same home-screen Quick Question route after the
// sheet has actually disappeared.
openQuickQuestionFromHomeScreen()
XCTAssertTrue(prompt.waitForExistence(timeout: 10))
XCTAssertTrue(app.keyboards.firstMatch.waitForExistence(timeout: 10))
XCTAssertEqual(prompt.value as? String, "retained draft")
// The field is already focused with its initial draft selected. Do not tap
// it here: typing immediately is the behavior under test.
prompt.typeText("replacement")
XCTAssertEqual(prompt.value as? String, "replacement")
}
private func quickQuestionPrompt() -> XCUIElement {
app.textFields["Ask anything..."]
}
private func dismissQuickQuestion() {
let header = app.staticTexts["Quick question"]
XCTAssertTrue(header.waitForExistence(timeout: 5))
let dismissStart = header.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5))
let dismissEnd = app.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.9))
dismissStart.press(forDuration: 0.1, thenDragTo: dismissEnd)
}
private func openQuickQuestionFromHomeScreen() {
XCUIDevice.shared.press(.home)
let sybilIcon = springboard.icons.matching(identifier: "Sybil").firstMatch
XCTAssertTrue(sybilIcon.waitForExistence(timeout: 10))
let homeScreen = springboard.otherElements["Home screen icons"]
if !sybilIcon.isHittable, homeScreen.waitForExistence(timeout: 5) {
for _ in 0..<2 where !sybilIcon.isHittable {
homeScreen.swipeLeft()
}
}
XCTAssertTrue(sybilIcon.isHittable, "Navigate to the home-screen page containing Sybil before opening its quick action.")
sybilIcon.press(forDuration: 1.2)
let quickQuestion = springboard.buttons["Quick question"]
@@ -53,19 +92,6 @@ final class QuickQuestionSelectionUITests: XCTestCase {
quickQuestion.tap()
}
private func dismissQuickQuestion(_ prompt: XCUIElement) {
if app.keyboards.firstMatch.exists, app.scrollViews.firstMatch.exists {
app.scrollViews.firstMatch.swipeDown()
}
let grabber = app.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.08))
let lowerSheet = app.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.92))
grabber.press(forDuration: 0.1, thenDragTo: lowerSheet)
let dismissed = expectation(for: NSPredicate(format: "exists == false"), evaluatedWith: prompt)
wait(for: [dismissed], timeout: 5)
}
private func control(_ body: [String: Any]) async throws {
var request = URLRequest(url: URL(string: "http://127.0.0.1:8799/control")!)
request.httpMethod = "POST"