summaryrefslogtreecommitdiff
path: root/core/views.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-24 14:06:54 -0300
committerGabriel Schneider <[email protected]>2026-11-24 14:57:45 -0300
commit8d0b21544824051873950ddcae1d4aab027a01fc (patch)
tree4fd7ca54c65fab8c73df178b0e16fe339a414017 /core/views.zig
parente332c4c300bd39ba9b2da797391e37ddebda5319 (diff)
downloadpardes-8d0b21544824051873950ddcae1d4aab027a01fc.tar.gz
pardes-8d0b21544824051873950ddcae1d4aab027a01fc.zip
tests: a view's top read off a geometry it is not the view of (row scroll round 4, fault 1, TESTS FIRST, each failing on the base ynxykzrt): the release soak's panic (run 18 of 24, a client's drawOne: `index out of bounds: index 41, len 38` at core/File.zig fillBody `text[from..end]`) is a view drawn after ANOTHER VIEW's step moved the top: the step's `show` hands its next geometry the top's byte (`Pane.top_skip`, keyed for the geometry after the move) while the map stays the one made before it; a view that was where the first was (a client's view opened as a copy of the live one, the same size) has that map's key, so `geometry` returns early and the text pass takes `top_skip.at`, a byte of the OTHER view's top line, with no look at its key: views.zig "a view drawn after another view's step moved the top into a long wrapped line, the two alike before it: ..." panics on the base `index out of bounds: index 1584, len 5` (a probe run first, throwaway, every top_skip read checked against the walk: made by `show`, line 10 row 22, read for line 0); a STEP takes the same stale row (`topNow`): views.zig "a view's step after another view's step moved the top, the two alike before it: it scrolls from its own top's row, as a core loaded from the session (none of its geometry) does" (PageDown in the second view: expected 12, found 14 on the base: a session that drew and a client that did not step apart); and the tab width is not in the geometry's key (a Tab zeroes `geometry_key` but not `top_skip`, whose key matches again: a row start of the old width trusted; in bounds, a wrong row; 180 such reads in one Debug soak with the probe): File.zig "a view scrolled by rows into a line of tabs, the tab width changed after a frame: its body drawn from the row the new width makes, as a core loaded from it draws it" fails on the base (rows from the 8-cell width's byte 27, the 2-cell width's is 74); and a second derived reader of the same kind, found by the table of every reader of a pane's geometry (normal.zig `gotoWindow` read `context_rows` before `shownRows` made the geometry): normal.zig "gt after a step that moved the view off the place its geometry was made for: ..." (two notches up off the held headers, then gt: expected 3, found 5 on the base: the session read the held rows of the place before the notch)
Co-Authored-By: Claude Opus <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/views.zig')
-rw-r--r--core/views.zig90
1 files changed, 90 insertions, 0 deletions
diff --git a/core/views.zig b/core/views.zig
index 4c020981..5ad9b749 100644
--- a/core/views.zig
+++ b/core/views.zig
@@ -898,6 +898,96 @@ test "a view drawn while another is live keeps its own cursors" {
try testing.expectEqual(@as(u16, 1), pane.body.nsel);
}
+test "a view drawn after another view's step moved the top into a long wrapped line, the two alike before it: drawn from its own top, line 0, not from the row the step found in the other's line" {
+ const gpa = testing.allocator;
+ const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 });
+ defer p.deinit();
+ // A short first line, and line 10 wrapped over more rows than the body.
+ var text: std.ArrayList(u8) = .empty;
+ defer text.deinit(gpa);
+ try text.appendSlice(gpa, "short\n");
+ for (1..10) |i| try text.print(gpa, "line {d}\n", .{i});
+ for (0..500) |w| try text.print(gpa, "w{d:0>4} ", .{w});
+ try text.appendSlice(gpa, "\nlast\n");
+ const pane = try p.setTestFile(text.items);
+ const k = p.openView().?;
+ // View 0's step puts the cursor at line 10's end: the top goes into
+ // that line's rows, a row far past line 0's five bytes. View k is
+ // where view 0 was: its top line 0, its size view 0's.
+ pane.body.cur_row = 10;
+ pane.body.cur_col = @intCast(pardes.panes.File.sourceLine(pane, 10).len - 1);
+ pane.body.cur_pinned = true;
+ pane.ensureCursorVisible(p.settings.tab);
+ p.sync();
+ try testing.expectEqual(@as(usize, 10), pane.file.?.scroll);
+ try testing.expect(pane.file.?.scroll_row > 0);
+ const Seen = struct {
+ short: bool = false,
+ fn present(ctx: ?*anyopaque, s: *const pardes.Surface) bool {
+ const seen: *@This() = @ptrCast(@alignCast(ctx.?));
+ var row: [512]u8 = undefined;
+ for (0..s.rows) |y| {
+ var n: usize = 0;
+ for (s.cells[y * s.cols ..][0..s.cols]) |c| {
+ if (n + c.len > row.len) break;
+ @memcpy(row[n..][0..c.len], c.text[0..c.len]);
+ n += c.len;
+ }
+ if (std.mem.indexOf(u8, row[0..n], "short") != null) seen.short = true;
+ }
+ return true;
+ }
+ };
+ var seen: Seen = .{};
+ _ = try drawOne(p, k.index(), .{ .ctx = &seen, .f = Seen.present });
+ try testing.expect(seen.short);
+}
+
+test "a view's step after another view's step moved the top, the two alike before it: it scrolls from its own top's row, as a core loaded from the session (none of its geometry) does" {
+ const gpa = testing.allocator;
+ const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 });
+ defer p.deinit();
+ // Line 3 wrapped over several rows, line 10 over more than the body.
+ var text: std.ArrayList(u8) = .empty;
+ defer text.deinit(gpa);
+ for (0..12) |i| switch (i) {
+ 3, 10 => {
+ for (0..@as(usize, if (i == 3) 60 else 500)) |w| try text.print(gpa, "w{d:0>4} ", .{w});
+ try text.append(gpa, '\n');
+ },
+ else => try text.print(gpa, "line {d}\n", .{i}),
+ };
+ const pane = try p.setTestFile(text.items);
+ const f = &pane.file.?;
+ // Both views' top on line 3's third row, the cursor on it.
+ pane.body.cur_row = 3;
+ pane.body.cur_col = 150;
+ f.scroll = 3;
+ f.scroll_row = 2;
+ p.sync();
+ const k = p.openView().?;
+ // View 0's step: the cursor to line 10's end, the top into its rows.
+ pane.body.cur_row = 10;
+ pane.body.cur_col = @intCast(pardes.panes.File.sourceLine(pane, 10).len - 1);
+ pane.body.cur_pinned = true;
+ pane.ensureCursorVisible(p.settings.tab);
+ p.sync();
+ try testing.expect(f.scroll == 10 and f.scroll_row > 2);
+ // The session as a client joining it loads it: no geometry made.
+ const bytes = try pardes.dump.dumpBytes(p);
+ defer gpa.free(bytes);
+ const loaded = try pardes.dump.load(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 }, bytes, null);
+ defer loaded.deinit();
+ // View k's PageDown in each, from line 3's third row.
+ for ([_]*Pardes{ p, loaded }) |core| {
+ core.toView(k);
+ core.update(.{ .key = .{ .cp = pardes.Key.page_down } });
+ }
+ const lf = &loaded.panes[0].?.file.?;
+ try testing.expectEqual(lf.scroll, f.scroll);
+ try testing.expectEqual(lf.scroll_row, f.scroll_row);
+}
+
test "a view not live keeps its place in a text another view edits" {
const gpa = testing.allocator;
const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 });