oficina / sheets Public

Mac: with always-shown scroll bars, the last row and column scroll clear of them

#72, Fable's review of 58b4cb0, finding 3. Legacy scroll bars sit over the
content's last strip, and the scroll geometry counts that strip as
visible, so revealing the last row or column (BH120 on the mixed test
sheet) stopped one bar-width short, the cell and its editor under both
bars. The content now carries trailing and bottom padding of the bar width
in that style (none with overlay scroll bars).

testTypingOnAFarCellScrollsExactlyToIt now includes the last cell, BH120,
and fails without this; the exact-size test counts the padding.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev 11580e1632ce9038eb93cbeb1c151140f86ac594 parent 48f8d5f
2 files changed, +18 −7
  • native/apple/Sources/SheetsKit/SheetGrid.swift +11 −4
  • native/apple/Tests/SheetsKitTests/GridGeometryTests.swift +7 −3
diff --git a/native/apple/Sources/SheetsKit/SheetGrid.swift b/native/apple/Sources/SheetsKit/SheetGrid.swift
index 8676be7..ddd10e2 100644
--- a/native/apple/Sources/SheetsKit/SheetGrid.swift
+++ b/native/apple/Sources/SheetsKit/SheetGrid.swift
@@ -373,6 +373,10 @@ struct SheetGridContent: View, Equatable {
frame: m.frame, end: actions.endEditing)
}
#endif
+ // Always-shown scroll bars sit over the content's last strip; without
+ // room for them the last row and column could never be scrolled clear.
+ .padding(.trailing, SheetGridScroller.legacyBar)
+ .padding(.bottom, SheetGridScroller.legacyBar)
}
.defaultScrollAnchor(.topLeading)
.scrollPosition($position)
@@ -509,12 +513,15 @@ struct SheetResizePreview: Equatable {
/// counts the area under them; with legacy (always shown) scroll bars on
/// the Mac, a cell revealed into that strip would be hidden by them.
static func usable(_ rect: CGRect) -> CGRect {
- #if os(macOS)
- guard NSScroller.preferredScrollerStyle == .legacy else { return rect }
- let bar = NSScroller.scrollerWidth(for: .regular, scrollerStyle: .legacy)
+ let bar = legacyBar
return CGRect(x: rect.minX, y: rect.minY, width: rect.width - bar, height: rect.height - bar)
+ }
+ /// The width of an always-shown scroll bar, or 0 with overlay scroll bars.
+ static var legacyBar: Double {
+ #if os(macOS)
+ NSScroller.preferredScrollerStyle == .legacy ? NSScroller.scrollerWidth(for: .regular, scrollerStyle: .legacy) : 0
#else
- return rect
+ 0
#endif
}
/// The content offset that brings `frame` into view with the least scroll,
diff --git a/native/apple/Tests/SheetsKitTests/GridGeometryTests.swift b/native/apple/Tests/SheetsKitTests/GridGeometryTests.swift
index 1cf5ee4..d77b2fb 100644
--- a/native/apple/Tests/SheetsKitTests/GridGeometryTests.swift
+++ b/native/apple/Tests/SheetsKitTests/GridGeometryTests.swift
@@ -70,8 +70,10 @@ final class GridGeometryTests: XCTestCase {
defer { window.orderOut(nil) }
let m = metrics(model)
let document = try XCTUnwrap(scroll.documentView).frame.size
- XCTAssertEqual(document.width, SheetGridMetrics.rowHeader + m.cellsWidth, accuracy: 0.5)
- XCTAssertEqual(document.height, SheetGridMetrics.colHeader + m.cellsHeight, accuracy: 0.5)
+ // Plus room for always-shown scroll bars, when they are.
+ let bar = SheetGridScroller.legacyBar
+ XCTAssertEqual(document.width, SheetGridMetrics.rowHeader + m.cellsWidth + bar, accuracy: 0.5)
+ XCTAssertEqual(document.height, SheetGridMetrics.colHeader + m.cellsHeight + bar, accuracy: 0.5)
XCTAssertEqual(scroll.contentView.bounds.origin, .zero, "mixed widths opened pre-scrolled")
}
@@ -110,7 +112,9 @@ final class GridGeometryTests: XCTestCase {
let (window, host, scroll) = try await open(model)
defer { window.orderOut(nil) }
let m = metrics(model)
- for target in [Coordinate(r: 90, c: 50), Coordinate(r: 3, c: 1), Coordinate(r: 61, c: 33)] {
+ // Including the last cell, BH120: with always-shown scroll bars it
+ // stopped one bar short, under both bars.
+ for target in [Coordinate(r: 90, c: 50), Coordinate(r: 3, c: 1), Coordinate(r: 61, c: 33), Coordinate(r: 119, c: 59)] {
model.select(target)
key("z", 6, window)
try await Task.sleep(for: .milliseconds(400))