Keep Mac question drafts through row rebuilds and submit on Return
Co-Authored-By: Codex GPT-6-Astra <noreply@openai.com>
4 files changed,
+87
−7
native/PROJECTS-REPORT.md+8 −0native/apple/Sources/EquipoMac/LiveTranscript.swift+5 −7native/apple/Sources/EquipoMac/QuestionAnswerField.swift+32 −0native/apple/Tests/EquipoKitTests/ProjectsMacQuestionTests.swift+42 −0
diff --git a/native/PROJECTS-REPORT.md b/native/PROJECTS-REPORT.md| index b8f0bc50..c89c97ad 100644 |
| --- a/native/PROJECTS-REPORT.md |
| +++ b/native/PROJECTS-REPORT.md |
| @@ -299,3 +299,11 @@ A seven-case regression covers genuine project loss, other codes, foreign copy |
| keys, plain HTTP 404s, another status, no project, and task threads. It failed |
| first, passed after the fix, and caught separate code and copy-key mutations. |
| Unrelated failures retain the original retry body and key. |
| + |
| +P3 ordinary Mac question: QuestionAnswerField stores every text edit in the |
| +card's existing draft. Return and the Answer button share its submit action. |
| +The regression types through the actual field delegate, changes the transcript |
| +width to replace the row, checks the restored text, and sends Return through |
| +the replacement field's delegate. It verifies the answer text and revision on |
| +the transport. The initial implementation failed all four boundaries; live |
| +edit and Return mutations each fail after the fix. |
diff --git a/native/apple/Sources/EquipoMac/LiveTranscript.swift b/native/apple/Sources/EquipoMac/LiveTranscript.swift| index 8c342076..a228dbdb 100644 |
| --- a/native/apple/Sources/EquipoMac/LiveTranscript.swift |
| +++ b/native/apple/Sources/EquipoMac/LiveTranscript.swift |
| @@ -391,19 +391,17 @@ final class LiveTranscript: NSView { |
| let sending: String? = { if case .sending(let id) = state { return id }; return nil }() |
| let options = card.options ?? [] |
| if options.isEmpty { |
| - let field = NSTextField(string: session.questionDraft(for: card).typedChoice) |
| + let field = QuestionAnswerField(draft: session.questionDraft(for: card)) { [weak self] choice in |
| + self?.submit(card: card, choice: choice) |
| + } |
| field.placeholderString = EquipoStrings.text("chat.card.answer") |
| field.setAccessibilityLabel(EquipoStrings.text("chat.card.answer")) |
| field.font = MacType.line; field.textColor = .webText |
| field.frame.size = NSSize(width: inner, height: 32) |
| field.isEnabled = sending == nil |
| add(field) |
| - let answer = button(EquipoStrings.text("chat.card.answer"), .primary) { [weak self, weak field] in |
| - guard let self, let field else { return } |
| - let text = field.stringValue.trimmingCharacters(in: .whitespacesAndNewlines) |
| - guard !text.isEmpty else { return } |
| - self.session.questionDraft(for: card).typedChoice = text |
| - self.submit(card: card, choice: text) |
| + let answer = button(EquipoStrings.text("chat.card.answer"), .primary) { [weak field] in |
| + field?.submit() |
| } |
| answer.frame.size = NSSize(width: inner, height: 32); add(answer) |
| } else { |
diff --git a/native/apple/Sources/EquipoMac/QuestionAnswerField.swift b/native/apple/Sources/EquipoMac/QuestionAnswerField.swift| new file mode 100644 |
| index 00000000..5edfba82 |
| --- /dev/null |
| +++ b/native/apple/Sources/EquipoMac/QuestionAnswerField.swift |
| @@ -0,0 +1,32 @@ |
| +import AppKit |
| +import EquipoKit |
| + |
| +/// The text belongs to the card, so replacing a row never discards an edit. |
| +@MainActor final class QuestionAnswerField: NSTextField, NSTextFieldDelegate { |
| + private let draft: QuestionAnswerDraft |
| + private let onSubmit: (String) -> Void |
| + |
| + init(draft: QuestionAnswerDraft, onSubmit: @escaping (String) -> Void) { |
| + self.draft = draft; self.onSubmit = onSubmit |
| + super.init(frame: .zero) |
| + stringValue = draft.typedChoice |
| + delegate = self |
| + } |
| + required init?(coder: NSCoder) { fatalError() } |
| + |
| + func controlTextDidChange(_ notification: Notification) { |
| + draft.typedChoice = stringValue |
| + } |
| + func control(_ control: NSControl, textView: NSTextView, doCommandBy selector: Selector) -> Bool { |
| + guard selector == #selector(NSResponder.insertNewline(_:)) else { return false } |
| + submit() |
| + return true |
| + } |
| + func submit() { |
| + guard isEnabled else { return } |
| + let text = stringValue.trimmingCharacters(in: .whitespacesAndNewlines) |
| + guard !text.isEmpty else { return } |
| + draft.typedChoice = stringValue |
| + onSubmit(text) |
| + } |
| +} |
diff --git a/native/apple/Tests/EquipoKitTests/ProjectsMacQuestionTests.swift b/native/apple/Tests/EquipoKitTests/ProjectsMacQuestionTests.swift| new file mode 100644 |
| index 00000000..0d258c37 |
| --- /dev/null |
| +++ b/native/apple/Tests/EquipoKitTests/ProjectsMacQuestionTests.swift |
| @@ -0,0 +1,42 @@ |
| +#if os(macOS) |
| +import AppKit |
| +import SwiftUI |
| +import Testing |
| +@testable import EquipoKit |
| +@testable import EquipoMac |
| + |
| +@MainActor @Suite(.serialized) struct ProjectsMacQuestionTests { |
| + @Test func ordinaryQuestionKeepsLiveDraftAcrossResizeAndReturnSubmits() async throws { |
| + let t = ScriptedTransport(); let s = try ProjectsReviewTests().session(t) |
| + var card: ThinCard = try Fixture.decode("project-card") |
| + card.placementByName = nil; card.rememberName = nil |
| + let byline = RosterByline(who: .coordinator, verb: "asks", project: nil, time: nil) |
| + t.on("POST /cards/\(card.id)/answer", fixture: "project-invalid", status: 422) |
| + let view = LiveTranscript(session: s, openTask: { _ in }) |
| + view.frame = NSRect(x: 0, y: 0, width: 700, height: 800) |
| + let window = NSWindow(contentRect: view.frame, styleMask: [.borderless], backing: .buffered, defer: false) |
| + window.contentView = view |
| + defer { window.contentView = nil } |
| + view.update(items: [.question(card, byline)]); view.layout() |
| + func fields(_ v: NSView) -> [NSTextField] { (v as? NSTextField).map { [$0] } ?? v.subviews.flatMap(fields) } |
| + func answerField() throws -> NSTextField { |
| + try #require(fields(view).first { $0.isEditable && $0.placeholderString == EquipoStrings.text("chat.card.answer") }) |
| + } |
| + let first = try answerField() |
| + first.stringValue = "The answer I am still writing" |
| + first.delegate?.controlTextDidChange?(Notification(name: NSControl.textDidChangeNotification, object: first)) |
| + #expect(s.questionDraft(for: card).typedChoice == first.stringValue) |
| + view.frame.size.width = 500; view.layout() |
| + let rebuilt = try answerField() |
| + #expect(rebuilt !== first, "exercise an actual row rebuild") |
| + #expect(rebuilt.stringValue == "The answer I am still writing") |
| + let handled = rebuilt.delegate?.control?(rebuilt, textView: NSTextView(), doCommandBy: #selector(NSResponder.insertNewline(_:))) |
| + #expect(handled == true) |
| + for _ in 0..<200 where t.sent("POST /cards/\(card.id)/answer").isEmpty { await Task.yield() } |
| + let request = try #require(t.sent("POST /cards/\(card.id)/answer").first) |
| + let fields = try #require(JSONSerialization.jsonObject(with: request.body!) as? [String: Any]) |
| + #expect(fields["choice"] as? String == "The answer I am still writing") |
| + #expect(fields["revision"] as? Int64 == card.revision) |
| + } |
| +} |
| +#endif |