From 430914371acd3fe46c31d7be900214e7ea03f657 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Mon, 6 Jul 2026 14:49:20 -0300 Subject: look on path:NN centers the target line in the pane body (scroll = line - body/2, clamped at 0): fresh opens lay out first (computeGeom after placeDoc) to center with the real body height; dedup re-looks recenter the existing pane. look-file golden shifts accordingly; new look-center snap proves fresh-open centering, dedup recentering, and the top clamp. --- src/pardes.zig | 7 ++- test/snapshots/look-center.golden | 93 +++++++++++++++++++++++++++++++++++++++ test/snapshots/look-center.snap | 28 ++++++++++++ test/snapshots/look-file.golden | 12 ++--- 4 files changed, 133 insertions(+), 7 deletions(-) create mode 100644 test/snapshots/look-center.golden create mode 100644 test/snapshots/look-center.snap diff --git a/src/pardes.zig b/src/pardes.zig index c4893b25..5b677250 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -2631,7 +2631,7 @@ pub const Pardes = struct { if (slot) |tt| if (tt.file) |*ff| if (std.mem.eql(u8, ff.path, target.path)) { p.active = i; if (target.line > 0 and target.line <= fileLineCount(ff.content)) { - const next = target.line - 1; + const next = (target.line - 1) -| tt.rows / 2; // center, clamp at top if (next != ff.scroll) { ff.scroll = next; ff.syntax_dirty = true; @@ -2643,6 +2643,11 @@ pub const Pardes = struct { const free = p.freeSlot() orelse return; const nt = p.openFileView(free, target.path, target.line) catch return; p.placeDoc(id, free, nt); + // center the target line: the pane's real body height only + // exists after placement, so lay out now and pull the + // scroll up by half a body (line 0 opens stay at the top) + p.computeGeom(); + nt.file.?.scroll -|= @max(1, p.rects[free].h -| BOX_H) / 2; }, .image => |target| { for (p.panes, 0..) |slot, i| { diff --git a/test/snapshots/look-center.golden b/test/snapshots/look-center.golden new file mode 100644 index 00000000..f2fe15a4 --- /dev/null +++ b/test/snapshots/look-center.golden @@ -0,0 +1,93 @@ +== snap center-open grid=100x30 cursor=7,6 +|Kill Newcol Tutor Debug Colors NextColor Dump +| nm /tmp/pardes-snap/look-center/cwd/big.txt Save nm /tmp/pardes-snap/look-center/cwd Del +| 96 line 96 +| 97 line 97 big.txt +| 98 line 98 +| 99 line 99 +| 100 line 100 +| 101 line 101 +| 102 line 102 +| 103 line 103 +| 104 line 104 +| nm /tmp/pardes-snap/look-center/cwd Del +| +| big.txt +| +| +| +| big.txt:100 big.txt:150 big.txt:2 +| +| +| +| nm /tmp/pardes-snap/look-center/cwd Del +| +| big.txt +| +| +| +| +| +| +== snap center-dedup grid=100x30 cursor=4,17 +|Kill Newcol Tutor Debug Colors NextColor Dump +| nm /tmp/pardes-snap/look-center/cwd/big.txt Save nm /tmp/pardes-snap/look-center/cwd Del +| 146 line 146 +| 147 line 147 big.txt +| 148 line 148 +| 149 line 149 +| 150 line 150 +| 151 line 151 +| 152 line 152 +| 153 line 153 +| 154 line 154 +| nm /tmp/pardes-snap/look-center/cwd Del +| +| big.txt +| +| +| +| big.txt:100 big.txt:150 big.txt:2 +| +| +| +| nm /tmp/pardes-snap/look-center/cwd Del +| +| big.txt +| +| +| +| +| +| +== snap center-clamp grid=100x30 cursor=4,17 +|Kill Newcol Tutor Debug Colors NextColor Dump +| nm /tmp/pardes-snap/look-center/cwd/big.txt Save nm /tmp/pardes-snap/look-center/cwd Del +| 1 line 1 +| 2 line 2 big.txt +| 3 line 3 +| 4 line 4 +| 5 line 5 +| 6 line 6 +| 7 line 7 +| 8 line 8 +| 9 line 9 +| nm /tmp/pardes-snap/look-center/cwd Del +| +| big.txt +| +| +| +| big.txt:100 big.txt:150 big.txt:2 +| +| +| +| nm /tmp/pardes-snap/look-center/cwd Del +| +| big.txt +| +| +| +| +| +| diff --git a/test/snapshots/look-center.snap b/test/snapshots/look-center.snap new file mode 100644 index 00000000..db575844 --- /dev/null +++ b/test/snapshots/look-center.snap @@ -0,0 +1,28 @@ +# a look on path:NN opens the file with the target line CENTERED in the body +# (scroll = line - body/2): fresh open at a deep line, then dedup re-looks at +# the same path re-center the existing pane, and a look near line 1 clamps +# the scroll at 0 (no negative scroll) +lines big.txt 200 +start 30 100 +wait 8000 big.txt +stable 700 20000 +press left 5 8 +release left 5 8 +stable 400 5000 +key i +text big.txt:100 big.txt:150 big.txt:2 +key esc +settle 700 +stable 400 5000 +press right 7 8 +release right 7 8 +stable 700 15000 +snap center-open +press right 18 18 +release right 18 18 +stable 700 15000 +snap center-dedup +press right 30 18 +release right 30 18 +stable 700 15000 +snap center-clamp diff --git a/test/snapshots/look-file.golden b/test/snapshots/look-file.golden index 4f6d4a71..5e8166c7 100644 --- a/test/snapshots/look-file.golden +++ b/test/snapshots/look-file.golden @@ -1,15 +1,15 @@ -== snap file-open grid=100x30 cursor=7,2 +== snap file-open grid=100x30 cursor=7,6 |Kill Newcol Tutor Debug Colors NextColor Dump | nm /tmp/pardes-snap/look-file/cwd/big.txt Save D nm /tmp/pardes-snap/look-file/cwd Del +| 36 line 36 +| 37 line 37 big.txt +| 38 line 38 +| 39 line 39 | 40 line 40 -| 41 line 41 big.txt +| 41 line 41 | 42 line 42 | 43 line 43 | 44 line 44 -| 45 line 45 -| 46 line 46 -| 47 line 47 -| 48 line 48 | nm /tmp/pardes-snap/look-file/cwd Del | | big.txt -- cgit v1.3