summaryrefslogtreecommitdiff
path: root/core/layout.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-23 18:26:46 -0300
committerGabriel Schneider <[email protected]>2026-11-23 23:34:56 -0300
commitdefafb5ccce2ae30d3e16cc8fb57fb73485e03f4 (patch)
tree53cbc7360ca4630013617215a322dcef0f4fd15a /core/layout.zig
parentcdab9ba0f0fdb433217f6b408ef81357176fa965 (diff)
downloadpardes-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/layout.zig')
-rw-r--r--core/layout.zig35
1 files changed, 31 insertions, 4 deletions
diff --git a/core/layout.zig b/core/layout.zig
index 4c7d6afb..7fa57ee9 100644
--- a/core/layout.zig
+++ b/core/layout.zig
@@ -845,10 +845,14 @@ fn bodyRows(p: *const Pardes, id: usize) u16 {
fn blankRows(p: *const Pardes, id: usize) u16 {
const pane = p.panes[id].?;
const rows = bodyRows(p, id);
- const used: usize = if (pane.file) |*f|
- // The empty line after a final newline shows nothing.
- (panes.File.nlines(p.gpa, f) -| @intFromBool(std.mem.endsWith(u8, f.content, "\n"))) -| f.scroll
- else if (pane.isTerminal())
+ const used: usize = if (pane.file) |*f| used: {
+ // The rows from the view's top to the text's end, a wrapped line's
+ // each; the empty line after a final newline shows nothing.
+ const end = panes.File.nlines(p.gpa, f) -| @intFromBool(std.mem.endsWith(u8, f.content, "\n"));
+ const top = panes.File.top(p.settings.tab, pane);
+ if (end <= top.line) break :used 0;
+ break :used @intCast(panes.File.rowsTo(p.settings.tab, pane, top, end, rows) orelse rows);
+ } else if (pane.isTerminal())
@as(usize, panes.Term.grid(pane.terminal).cursor_y) + 1
else
rows;
@@ -2158,3 +2162,26 @@ test "tiny screens keep pane space before adding a column tag" {
try std.testing.expectEqual(TOPBAR_H, p.view().rects[0].y);
_ = try p.render(p.scratch.allocator());
}
+
+test "a new pane goes below the rows a pane's text takes, a wrapped line's each counted: a pane whose few lines fill its rows keeps them all" {
+ const gpa = std.testing.allocator;
+ const io = std.testing.io;
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(io, .{ .sub_path = "b.txt", .data = "other\n" });
+ 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;
+ // Two lines of 400 bytes: seven rows each at this width.
+ const long = &@as([400]u8, @splat('a'));
+ const pane = try p.setTestFile(long ++ "\n" ++ long ++ "\n");
+ const a = p.view().active;
+ const used = panes.File.lineRows(p.settings.tab, pane, 0) + panes.File.lineRows(p.settings.tab, pane, 1);
+ try std.testing.expect(used >= 12);
+ var line: [4200]u8 = undefined;
+ p.update(.{ .command = try std.fmt.bufPrint(&line, "Look {s}/b.txt", .{dir}) });
+ try std.testing.expect(p.view().active != a);
+ try std.testing.expect(p.view().rects[a].h -| pane.tag_rows >= used);
+}