Native: the status says Not saved, never Saved, beside a failed edit
Review #72 delta, finding 3: after a failure nothing is sending, so the status fell back to the last notice, often "Saved". Test: statusNeverSaysSavedBesideAFailedEdit (fails without this).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 files changed,
+52
−3
native/apple/Sources/SheetsKit/SheetWrites.swift+7 −3native/apple/Tests/SheetsKitTests/FirstKeystrokeTests.swift+29 −0native/apple/Tests/SheetsKitTests/OptimisticEditTests.swift+16 −0
diff --git a/native/apple/Sources/SheetsKit/SheetWrites.swift b/native/apple/Sources/SheetsKit/SheetWrites.swift| index 20646c8..f4f6177 100644 |
| --- a/native/apple/Sources/SheetsKit/SheetWrites.swift |
| +++ b/native/apple/Sources/SheetsKit/SheetWrites.swift |
| @@ -56,10 +56,14 @@ struct PendingEdit: Sendable, Equatable { |
| var hasFailedEdits: Bool { pending.values.contains { $0.state == .failed } } |
| var isSending: Bool { pending.values.contains { $0.state != .failed } } |
| - /// The status bar's words: an edit being typed, edits on their way, or the |
| - /// last outcome. "Saved" only once nothing is left to send. |
| + /// The status bar's words: an edit being typed, edits on their way, edits |
| + /// not saved, or the last outcome. "Saved" only once nothing is left to |
| + /// send and nothing failed. |
| var saveStatus: String { |
| - dirty ? "Unsaved cell edit" : isSending ? sheetsMacString("Saving…") : notice |
| + if dirty { return "Unsaved cell edit" } |
| + if isSending { return sheetsMacString("Saving…") } |
| + if hasFailedEdits { return sheetsMacString("Not saved") } |
| + return notice |
| } |
| static func keepAlive() -> (@MainActor () -> Void) { |
diff --git a/native/apple/Tests/SheetsKitTests/FirstKeystrokeTests.swift b/native/apple/Tests/SheetsKitTests/FirstKeystrokeTests.swift| index 8f3a1d7..0777420 100644 |
| --- a/native/apple/Tests/SheetsKitTests/FirstKeystrokeTests.swift |
| +++ b/native/apple/Tests/SheetsKitTests/FirstKeystrokeTests.swift |
| @@ -253,6 +253,35 @@ final class FirstKeystrokeTests: XCTestCase { |
| } |
| } |
| + /// Review #72 delta, finding 6: on a wide sheet the first key took up to |
| + /// 900 ms to reach the cell's field. First key to glyph (the key's text in |
| + /// the cell's draft) must not grow with the sheet's width. |
| + @MainActor func testFirstKeyReachesTheFieldWithinFramesOnWideSheets() async throws { |
| + var report: [String] = [] |
| + for cols in [10, 60, 200] { |
| + var samples: [Double] = [] |
| + for attempt in 0..<4 { |
| + let model = fixtureModel(SheetServerFixture(), rows: 120, cols: cols) |
| + let (window, _) = try await host(model) |
| + let point = Coordinate(r: 1 + attempt, c: 1) |
| + model.select(point) |
| + try await Task.sleep(for: .milliseconds(150)) |
| + let start = ProcessInfo.processInfo.systemUptime |
| + key("x", code: 7, window: window) |
| + while model.draft != "x", ProcessInfo.processInfo.systemUptime - start < 3 { |
| + try await Task.sleep(for: .milliseconds(1)) |
| + } |
| + samples.append((ProcessInfo.processInfo.systemUptime - start) * 1000) |
| + XCTAssertEqual(model.draft, "x", "\(cols) columns: the key never arrived") |
| + window.orderOut(nil) |
| + } |
| + let median = samples.sorted()[samples.count / 2] |
| + report.append("\(cols) cols: median \(String(format: "%.1f", median)) ms \(samples.map { String(format: "%.0f", $0) })") |
| + XCTAssertLessThan(median, 100, "\(cols) columns") |
| + } |
| + print("MEASURE first key to glyph: " + report.joined(separator: "; ")) |
| + } |
| + |
| @MainActor func testWhichKeysStartTyping() { |
| func event(_ chars: String, _ ignoring: String, _ code: UInt16, _ flags: NSEvent.ModifierFlags = []) -> NSEvent { |
| NSEvent.keyEvent(with: .keyDown, location: .zero, modifierFlags: flags, timestamp: 0, windowNumber: 0, context: nil, characters: chars, charactersIgnoringModifiers: ignoring, isARepeat: false, keyCode: code)! |
diff --git a/native/apple/Tests/SheetsKitTests/OptimisticEditTests.swift b/native/apple/Tests/SheetsKitTests/OptimisticEditTests.swift| index 297f5de..1c9cc16 100644 |
| --- a/native/apple/Tests/SheetsKitTests/OptimisticEditTests.swift |
| +++ b/native/apple/Tests/SheetsKitTests/OptimisticEditTests.swift |
| @@ -325,3 +325,19 @@ private let b1 = Coordinate(r: 0, c: 1) |
| #expect(await eventually { model.cells[a1]?.raw == "landed" }, "the server's value, not the one from before the edit") |
| #expect(model.displayCell(a1)?.raw == "landed") |
| } |
| + |
| +// Review #72 delta, finding 3: never "Saved" beside an edit that was not. |
| +@MainActor @Test func statusNeverSaysSavedBesideAFailedEdit() async { |
| + let server = SheetServerFixture() |
| + let model = fixtureModel(server) |
| + type(model, a1, "ok") |
| + await model.settle() |
| + #expect(model.saveStatus == "Saved") |
| + server.refuseNext() |
| + type(model, a2, "refused") |
| + await model.settle() |
| + #expect(model.saveStatus == "Not saved") |
| + model.retryWrites() |
| + await model.settle() |
| + #expect(model.saveStatus == "Saved") |
| +} |