oficina / sheets Public

Mac and iOS: a floating cell editor is clipped below the pinned column header

Review #72 delta 2, finding 3. The editor (and the iOS key field while
typing) floats over the grid, so with its cell scrolled up under the
pinned column header it drew over the header. SheetHeaderClip masks it to
the area below; row headers scroll with the cells and never overlap one.

Test: testTheEditorStaysBelowThePinnedHeader compares the header strip
above the edited column with one far from it (fails without this).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev 6caec118117039062c718dc52e28406c60281715 parent 61f3bce
3 files changed, +45 −0
  • native/apple/Sources/SheetsKit/SheetCell.swift +1 −0
  • native/apple/Sources/SheetsKit/SheetGrid.swift +14 −0
  • native/apple/Tests/SheetsKitTests/GridGeometryTests.swift +30 −0
diff --git a/native/apple/Sources/SheetsKit/SheetCell.swift b/native/apple/Sources/SheetsKit/SheetCell.swift
index 63683d7..8e3a88b 100644
--- a/native/apple/Sources/SheetsKit/SheetCell.swift
+++ b/native/apple/Sources/SheetsKit/SheetCell.swift
@@ -122,6 +122,7 @@ struct SheetEditorOverlay: View {
.background(.background)
.overlay { Rectangle().strokeBorder(Color.accentColor, lineWidth: 2) }
.accessibilityLabel(String(format: sheetsMacString("Edit %@"), point.ref))
+ .modifier(SheetHeaderClip(window: window, top: box.minY))
.offset(x: box.minX, y: box.minY)
.id(point)
}
diff --git a/native/apple/Sources/SheetsKit/SheetGrid.swift b/native/apple/Sources/SheetsKit/SheetGrid.swift
index 75ca358..35a7c2c 100644
--- a/native/apple/Sources/SheetsKit/SheetGrid.swift
+++ b/native/apple/Sources/SheetsKit/SheetGrid.swift
@@ -419,6 +419,7 @@ struct SheetGridContent: View, Equatable {
let box = metrics.frame(model.selection.start)
return SheetKeySink(model: model, focusRequest: keyboardRequest, move: actions.move)
.frame(width: box.width, height: box.height)
+ .modifier(SheetHeaderClip(window: window, top: box.minY))
.offset(x: box.minX, y: box.minY)
.allowsHitTesting(false)
}
@@ -517,3 +518,16 @@ struct SheetResizePreview: Equatable {
return target == visible.origin ? nil : target
}
}
+
+/// Keeps a floating field (the cell editor, the iOS key field) below the
+/// pinned column header when its cell has scrolled under it.
+struct SheetHeaderClip: ViewModifier {
+ let window: SheetGridWindow
+ /// The field's top, in the grid's content coordinates.
+ let top: Double
+ func body(content: Content) -> some View {
+ content.mask(alignment: .topLeading) {
+ Rectangle().padding(.top, max(0, window.clipTop - top))
+ }
+ }
+}
diff --git a/native/apple/Tests/SheetsKitTests/GridGeometryTests.swift b/native/apple/Tests/SheetsKitTests/GridGeometryTests.swift
index b60f26d..1cf5ee4 100644
--- a/native/apple/Tests/SheetsKitTests/GridGeometryTests.swift
+++ b/native/apple/Tests/SheetsKitTests/GridGeometryTests.swift
@@ -126,6 +126,36 @@ final class GridGeometryTests: XCTestCase {
}
}
+ /// Review #72 delta 2, finding 3: an open editor scrolled up under the
+ /// pinned column header is clipped by it, not drawn over it.
+ @MainActor func testTheEditorStaysBelowThePinnedHeader() async throws {
+ let model = fixtureModel(SheetServerFixture(), rows: 60, cols: 10)
+ let (window, host, scroll) = try await open(model)
+ defer { window.orderOut(nil) }
+ model.select(Coordinate(r: 1, c: 1))
+ key("w", 13, window)
+ try await Task.sleep(for: .milliseconds(200))
+ XCTAssertNotNil(editorRect(host))
+ wheel(window, dx: 0, dy: -50)
+ try await Task.sleep(for: .milliseconds(300))
+ XCTAssertGreaterThan(scroll.contentView.bounds.minY, 20)
+ let bitmap = try XCTUnwrap(host.bitmapImageRepForCachingDisplay(in: host.bounds))
+ host.cacheDisplay(in: host.bounds, to: bitmap)
+ let scale = Double(bitmap.pixelsWide) / host.bounds.width
+ func colour(_ x: Double, _ yFromTop: Double) -> NSColor? {
+ bitmap.colorAt(x: Int(x * scale), y: Int(yFromTop * scale))?.usingColorSpace(.sRGB)
+ }
+ let visible = scroll.contentView.bounds
+ // Column B's header strip, above where the editor would draw, against
+ // column D's, which has no editor anywhere near it.
+ let m = metrics(model)
+ let b = m.frame(Coordinate(r: 1, c: 1)), d = m.frame(Coordinate(r: 1, c: 3))
+ let underB = try XCTUnwrap(colour(b.midX - visible.minX, 20))
+ let underD = try XCTUnwrap(colour(d.midX - visible.minX, 20))
+ XCTAssertEqual(underB.redComponent, underD.redComponent, accuracy: 0.03, "the editor drew over the pinned header")
+ XCTAssertEqual(underB.blueComponent, underD.blueComponent, accuracy: 0.03, "the editor drew over the pinned header")
+ }
+
@MainActor func testTheLeastScrollThatShowsACell() {
let visible = CGRect(x: 1000, y: 500, width: 600, height: 400)
XCTAssertNil(SheetGridScroller.offset(showing: CGRect(x: 1100, y: 600, width: 100, height: 30), in: visible))