@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
swift 53 lines 2.73 KB
Raw
1 // Exercise the real UIScrollView/geometry update path with a preceding large file.
2 private extension T3ReviewDiffView {
3 func checkRowAnchoring() throws {
4 frame = CGRect(x: 0, y: 0, width: 390, height: 600)
5 layoutSubviews()
6 setContentInsetTop(80)
7 let fixture = ["highlights.c", "simd128.h"].flatMap { file in
8 [["kind": "file", "id": "\(file):header", "fileId": file]] + (0..<100).map { line in
9 ["kind": "line", "id": "\(file):line:\(line)", "fileId": file,
10 "content": String(repeating: "long native code ", count: line % 9 + 1)]
11 }
12 }
13 rows = try JSONDecoder().decode([ReviewDiffNativeRow].self, from: JSONSerialization.data(withJSONObject: fixture))
14 contentView.rows = rows
15 updateContentMetrics()
16 let index = 130
17 func position(_ intra: CGFloat) {
18 setVerticalContentOffset(contentView.frameForRow(at: index)!.minY + intra, animated: false)
19 }
20 func assertPosition(_ intra: CGFloat, _ reason: String) {
21 let frame = contentView.frameForRow(at: index)!
22 let top = scrollView.contentOffset.y + scrollView.contentInset.top
23 check(top >= frame.minY && top < frame.maxY, "\(reason): visible row/file changed across geometry update")
24 check(abs(top - frame.minY - intra) < 0.01, "\(reason): intra-row position changed")
25 check(contentView.verticalOffset == scrollView.contentOffset.y, "Viewport and UIScrollView must agree")
26 }
27 position(7)
28 isProgrammaticScrollActive = true
29 contentView.isVerticalScrollActive = true
30 setStyleJson("{\"wordWrap\":true}")
31 assertPosition(7, "wrap on")
32 check(!isProgrammaticScrollActive && !contentView.isVerticalScrollActive,
33 "Anchor restoration must finish an interrupted programmatic scroll")
34 setStyleJson("{\"wordWrap\":true,\"codeFontSize\":22}")
35 assertPosition(7, "font change")
36 frame.size.width = 280
37 layoutSubviews()
38 assertPosition(7, "wrapped width change")
39 position(contentView.frameForRow(at: index)!.height - 2)
40 setStyleJson("{\"wordWrap\":false,\"rowHeight\":24}")
41 let height = contentView.frameForRow(at: index)!.height
42 assertPosition(height - 1, "unwrap clamps inside shortened row")
43 setInitialFileId("simd128.h")
44 layoutSubviews()
45 check(abs(scrollView.contentOffset.y + scrollView.contentInset.top - contentView.fileHeaderOffset(forFileId: "simd128.h")!) < 0.01,
46 "Explicit initial-file navigation must win over geometry anchoring")
47 setContentResetKey("new-content")
48 setStyleJson("{\"wordWrap\":true}")
49 check(rows.isEmpty && scrollView.contentOffset.y == -80, "Reset must discard the old anchor")
50 print("Passed viewport row anchors for wrap, font, width, intra-row clamp, initial file, and reset")
51 }
52 }
53 try T3ReviewDiffView().checkRowAnchoring()