diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-23 18:26:46 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-23 23:34:56 -0300 |
| commit | defafb5ccce2ae30d3e16cc8fb57fb73485e03f4 (patch) | |
| tree | 53cbc7360ca4630013617215a322dcef0f4fd15a /core/look.zig | |
| parent | cdab9ba0f0fdb433217f6b408ef81357176fa965 (diff) | |
| download | pardes-defafb5ccce2ae30d3e16cc8fb57fb73485e03f4.tar.gz pardes-defafb5ccce2ae30d3e16cc8fb57fb73485e03f4.zip | |
scroll: what still moved by lines now counts rows where a wrapped line made it wrong (P62 round 3, item 3): gt/gb land on the row `scroll_off` rows in from the body's top or its last row of text, a wrapped line's later row as any, the cursor on the first byte that row shows (helix's goto_window), where they went `scroll_off` LINES down from the top line (inside a wrapped line: a line far below, the view moved); gw labels the words of the bytes the body shows (`File.shownBytes`: its first row's first to its last row's last), none on a wrapped line's rows above the view's top (a word the first row starts inside of begins above it: its label would not show), where it labelled the words of `rows` lines from the top line's start; a new pane goes below the rows a pane's text takes (layout.zig `blankRows`: the rows from the view's top to the text's end, `File.rowsTo`, a wrapped line's each), where a pane of a few long lines counted a row a line and had the new pane laid over its text; a Look opening a file in a pane of its own puts its line half the body's rows down, a wrapped line's rows above it counted (look.zig, `walkRows`), where it went half the body's LINES up; TESTS FIRST, each failing on item 1's tree (`qwssppvo`) and passing here: core/normal.zig "gt and gb go to the row scroll_off rows in from the body's top and from its bottom, ..." (the view moved, row 4 to 5), "gw labels the words the body shows and no others: ..." (a label above the top), core/layout.zig "a new pane goes below the rows a pane's text takes, ..." (the pane kept fewer rows than its text), core/look.zig "a Look that opens a file in a pane of its own puts its line half the body's rows down, ..." (24 rows above it, not 17); STILL LINES, each right there: Places' first range (its search pieces are whole lines, so a match is never cut at a piece's edge, and `scroll + rows + 1` lines hold every row shown, each line at least one), the frames' `view` (a statistic's label: no decision reads it), the rail's thumb (rows would wrap the whole text at each width), the syntax window (the rows shown lie inside the lines `scroll .. scroll + rows`)
Co-Authored-By: Claude Opus <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/look.zig')
| -rw-r--r-- | core/look.zig | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/core/look.zig b/core/look.zig index f60b90f5..eee808cb 100644 --- a/core/look.zig +++ b/core/look.zig @@ -1605,11 +1605,13 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void { // miss of its line too. if (p.fs.failures != failures) return; layout.compute(p); - nt.file.?.scroll -|= @max(1, v.rects[free].h -| BOX_H) / 2; + // Its line half the body's rows down, a wrapped line's + // rows above it counted. + const centered = panes.File.walkRows(p.settings.tab, nt, .{ .line = nt.file.?.scroll }, -@as(i64, @max(1, v.rects[free].h -| BOX_H) / 2)).to; + panes.File.setTop(nt, centered); if (target.at.end_line != 0) { - const centered = nt.file.?.scroll; selectSpan(p, nt, target.at); - nt.file.?.scroll = centered; + panes.File.setTop(nt, centered); } opened = free; } @@ -1840,6 +1842,35 @@ test "lookableLineSpan prefers the longest run, so a blank inside a path is one ); } +test "a Look that opens a file in a pane of its own puts its line half the body's rows down, a wrapped line's rows above it counted" { + const gpa = std.testing.allocator; + const io = std.testing.io; + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + // Line 10 of 600 bytes, eleven rows or more in a pane 60 wide. + var text: std.ArrayList(u8) = .empty; + defer text.deinit(gpa); + for (0..60) |i| if (i == 10) { + try text.appendNTimes(gpa, 'a', 600); + try text.append(gpa, '\n'); + } else try text.print(gpa, "line {d:0>2}\n", .{i}); + try tmp.dir.writeFile(io, .{ .sub_path = "c.txt", .data = text.items }); + var buf: [std.Io.Dir.max_path_bytes]u8 = undefined; + const dir = buf[0..try tmp.dir.realPath(io, &buf)]; + const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 60, .rows = 40 }); + defer p.deinit(); + p.settings.wrap = true; + _ = try p.setTestFile("x\n"); + var line: [4200]u8 = undefined; + p.update(.{ .command = try std.fmt.bufPrint(&line, "Look {s}/c.txt:14", .{dir}) }); + const id = p.view().active; + const pane = p.panes[id].?; + try std.testing.expect(panes.File.lineRows(p.settings.tab, pane, 10) >= 11); + try std.testing.expectEqual(@as(i32, 13), pane.body.cur_row); + const half: i64 = @max(1, p.view().rects[id].h -| BOX_H) / 2; + try std.testing.expectEqual(half, panes.File.rowsTo(p.settings.tab, pane, panes.File.top(p.settings.tab, pane), 13, 100).?); +} + test "a miss names a long path by its start and its end, its middle given up to …" { var cut: [miss_path_cap + "…".len]u8 = undefined; const long = "/home/someone/" ++ std.mem.asBytes(&@as([80][5]u8, @splat("deep/".*))) ++ "the-file.zig"; |
