diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-24 14:06:54 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-24 14:57:45 -0300 |
| commit | 8d0b21544824051873950ddcae1d4aab027a01fc (patch) | |
| tree | 4fd7ca54c65fab8c73df178b0e16fe339a414017 | |
| parent | e332c4c300bd39ba9b2da797391e37ddebda5319 (diff) | |
| download | pardes-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
| -rw-r--r-- | core/File.zig | 28 | ||||
| -rw-r--r-- | core/normal.zig | 32 | ||||
| -rw-r--r-- | core/views.zig | 90 |
3 files changed, 150 insertions, 0 deletions
diff --git a/core/File.zig b/core/File.zig index 8e464d61..163f40ff 100644 --- a/core/File.zig +++ b/core/File.zig @@ -3679,3 +3679,31 @@ test "Syntax off in a patch's pane takes the language's ink and leaves the patch if (pass == 1) try std.testing.expect(differ); } } + +test "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" { + const gpa = std.testing.allocator; + const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 40, .rows = 12 }); + defer p.deinit(); + var text: std.ArrayList(u8) = .empty; + defer text.deinit(gpa); + try text.appendSlice(gpa, "head\n"); + for (0..40) |i| try text.print(gpa, "\tw{d}", .{i}); + try text.appendSlice(gpa, "\ntail\n"); + const pane = try p.setTestFile(text.items); + try std.testing.expect(p.executeBuiltinLine(0, "Tab 8")); + // The top on line 1's fourth row (at 8 cells a tab), drawn. + const f = &pane.file.?; + f.scroll = 1; + f.scroll_row = 3; + var arena: std.heap.ArenaAllocator = .init(gpa); + defer arena.deinit(); + _ = try p.render(arena.allocator()); + try std.testing.expect(p.executeBuiltinLine(0, "Tab 2")); + const drawn = try bodyText(p.settings.tab, arena.allocator(), pane, f); + const bytes = try pardes.dump.dumpBytes(p); + defer gpa.free(bytes); + const loaded = try pardes.dump.load(gpa, .{ .tty_only = true, .cols = 40, .rows = 12 }, bytes, null); + defer loaded.deinit(); + const lp = loaded.panes[0].?; + try std.testing.expectEqualStrings(try bodyText(loaded.settings.tab, arena.allocator(), lp, &lp.file.?), drawn); +} diff --git a/core/normal.zig b/core/normal.zig index fe0c729a..5a9794ee 100644 --- a/core/normal.zig +++ b/core/normal.zig @@ -1527,6 +1527,38 @@ test "gt and gb go to the row scroll_off rows in from the body's top and from it } } +test "gt after a step that moved the view off the place its geometry was made for: the row scroll_off in from the body's top under the context rows the view has now, as a core loaded from the session goes" { + const gpa = std.testing.allocator; + const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 60, .rows = 16 }); + defer p.deinit(); + const pane = try p.setTestFile("pub const Box = struct {\n pub fn run() void {\n" ++ (std.mem.asBytes(&@as([30][21]u8, @splat(" // body line\n".*)))) ++ " }\n};\n"); + p.gpa.free(pane.file.?.path); + pane.file.?.path = try p.gpa.dupe(u8, "/test.zig"); + if (!File.supportsContext(pane)) return error.SkipZigTest; + pane.file.?.tree_context = true; + // The view inside the function, its two headers held over the body, + // drawn. + File.setTop(pane, .{ .line = 3 }); + p.sync(); + var arena: std.heap.ArenaAllocator = .init(gpa); + defer arena.deinit(); + _ = try p.render(arena.allocator()); + try std.testing.expectEqual(@as(u16, 2), pane.context_rows); + // Two notches up: the top on the function's header, one header held + // (the geometry the second notch read was the one before it). + const rect = p.view().rects[0]; + for (0..2) |_| p.update(.{ .mouse = .{ .button = .wheel_up, .kind = .press, .col = rect.x + 10, .row = rect.y + 5 } }); + try std.testing.expectEqual(@as(usize, 1), pane.file.?.scroll); + const bytes = try pardes.dump.dumpBytes(p); + defer gpa.free(bytes); + const loaded = try pardes.dump.load(gpa, .{ .tty_only = true, .cols = 60, .rows = 16 }, bytes, null); + defer loaded.deinit(); + for ([_]*Pardes{ p, loaded }) |core| for ("gt") |k| core.update(.{ .key = .{ .cp = k, .text = &[_]u8{k} } }); + try std.testing.expectEqual(loaded.panes[0].?.body.cur_row, pane.body.cur_row); + try std.testing.expectEqual(@as(u16, 1), pane.context_rows); + try std.testing.expectEqual(pane.wrapAt(p.settings.tab, 1 + config.scroll_off).line, pane.body.cur_row); +} + test "gw labels the words the body shows and no others: none on a wrapped line's rows above the view's top" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 60, .rows = 24 }); defer p.deinit(); 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 }); |
