summaryrefslogtreecommitdiff
path: root/core/replica.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-23 18:00:35 -0300
committerGabriel Schneider <[email protected]>2026-11-23 18:20:56 -0300
commitb1fb4242c0ab52767df1b8e155edcf2692f37873 (patch)
treec5e10602471c331a0d462a35072d883d65140933 /core/replica.zig
parentdde58f770995dcbc929708048a6e0f390c70f8af (diff)
downloadpardes-b1fb4242c0ab52767df1b8e155edcf2692f37873.tar.gz
pardes-b1fb4242c0ab52767df1b8e155edcf2692f37873.zip
scroll: a view's top is a line and a row within that line's own wrapped rows, and a scroll moves it by rows (P62, round 3, on the layer's new model where the `Changes` layer's lines are lines of the buffer): a wheel's notch, the glide, PageDown/PageUp, zj/zk, Ctrl-d/u, zt/zz/zb and the margin (`scroll_off` now ROWS) go a row at a time through a line wrapped over many rows and through a long description line of the layer, where the base jumped all of a wrapped line's rows at once (the user, 2026-11-23: "the scroll view jumps around near deleted lines on the diff view"; one-row deleted lines were cured by the layer's second step, a wrapped one was not): TESTS FIRST: core/jj.zig "a view scrolls by rows through a line wrapped over 12 rows and a change's description wrapped over several (a line of the layer): ..." (a notch is one row down the whole text and back, the notches the text's rows exactly; PageDown/PageUp a page of rows; zj/zk one; a held j and k keep the cursor's row `scroll_off` rows inside the body) failing on the base at notch 21 (line 20's 12 rows crossed at once), and "a client wheels its session's view a row a notch into a change's description wrapped over several rows ..., agreeing at every notch; a client joined over that view loads its row"; kept from round 1: core/replica.zig's join over a view scrolled into a wrapped line (with a rollback and a dump) and the explorer of a view's rows (30 seeds), dev/gui's glide a row a notch; THE CHANGE, taken from pardes-row-scroll (`xrxmqlnw`) and -2 (`xxzmwnvq`) without their ghost-row "blocks" (a block is now just a line's own rows): `File.State.scroll_row` and `views.PaneView.scroll_row` in the generic walk (digested, dumped, copied; a dump of 34 loads at its lines' first rows), the wire 35; core/File.zig `Top`, `rowIn`/`rowWalked` (a line's rows as fillBody wraps them, `guideOf` shared), `rowOf`, `lineRows`, `top`/`setTop`, `walkRows`/`walkKnown`, `rowsTo`, `rowsOf` (off the map where it holds the line), `mapFresh`, `scrollRows`, `shownRows` (the geometry laid out first), `show` (a cursor's or a result's row inside the band, the line's rows whole when they fit), `textRowLine`, fillBody's skip to the top's row walked once a geometry (`Pane.top_skip`, derived), the geometry's key with `scroll_row` and stored as what the map was made from; the one-row fact `State.widest` (`Widest`, an upper bound kept by the index's own vector passes `countLines`/`fillLines`) so a view whose lines are each one row walks nothing (`oneRow`: line arithmetic, checked against the walk in Debug); `fitEnd` a vector of printable ASCII at a time; the callers in rows: panes.zig `scrollBy(tab, delta)` and `ensureCursorVisible` (a file's through `File.show`), the wheel and the rail and the edge scroll (mouse.zig), Ctrl-d/u (normal.zig `halfPageMove`), zt/zz/zb, Ctrl-f/b and PgUp/PgDn (Text.zig `scrollViewMove`), Look's reveal and centring, Places' `goTo`/`restore`, Query's `showCurrent`/`caretTo`, the frames' `Region.row` and the glide (dev/glide.zig, the window's `topOf`); test/perf.zig's checks by (line, row) and its seek at a line's first row; Debug in the workspace: core-test 963/1129 (166 skipped), shell-test 1172/1175 (3 skipped)
Co-Authored-By: Claude Opus <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/replica.zig')
-rw-r--r--core/replica.zig154
1 files changed, 154 insertions, 0 deletions
diff --git a/core/replica.zig b/core/replica.zig
index 57dd4eed..f62cd629 100644
--- a/core/replica.zig
+++ b/core/replica.zig
@@ -4491,6 +4491,160 @@ test "bytes: a client's wheel over a terminal is its own view's: applied at once
try std.testing.expect(placeIn(b.r.core(), b.r.view, id).? < back);
}
+test "a view's top is a line and a row of its block: a client's wheel into a line wrapped over rows moves it a row a notch, the session agrees through a rollback, and a dump keeps the row" {
+ const gpa = std.testing.allocator;
+ var text: std.ArrayList(u8) = .empty;
+ defer text.deinit(gpa);
+ // Line 3 is 60 words: four rows at this width.
+ for (0..40) |i| if (i == 3) {
+ for (0..60) |w| try text.print(gpa, "w{d:0>3} ", .{w});
+ try text.append(gpa, '\n');
+ } else try text.print(gpa, "line {d}\n", .{i});
+ const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host());
+ defer a.deinit();
+ const was = Stepping.begin(&a.t, null);
+ _ = try a.core.setTestFile(text.items);
+ was.end();
+ _ = try a.unit(0, 0);
+ const id = a.core.view().active;
+ // A client joined from the session's dump: the text is in it.
+ const r = try joinedNow(a, 1, 0);
+ defer r.deinit();
+ const rect = a.core.view().rects[id];
+ const notch: pardes.Event = .{ .mouse = .{ .button = .wheel_down, .kind = .press, .col = rect.x + 10, .row = rect.y + 5 } };
+ // Three notches to line 3's first row, two into its block.
+ for (0..5) |_| {
+ const m = try gpa.dupe(u8, try r.input(notch));
+ defer gpa.free(m);
+ r.confirm(try a.take(m));
+ r.settle();
+ try agrees(a, r);
+ }
+ for ([_]*Pardes{ a.core, r.core() }) |core| {
+ try std.testing.expectEqual(@as(usize, 3), core.panes[id].?.file.?.scroll);
+ try std.testing.expectEqual(@as(u32, 2), core.panes[id].?.file.?.scroll_row);
+ }
+ // A notch of the client's on top of the session's own key (one that
+ // leaves the view be): the copy put back, the notch applied over it.
+ const again = try gpa.dupe(u8, try r.input(notch));
+ defer gpa.free(again);
+ r.confirm(try a.local(.{ .key = .{ .cp = pardes.Key.escape } }));
+ r.settle();
+ r.confirm(try a.take(again));
+ r.settle();
+ try agrees(a, r);
+ try std.testing.expectEqual(@as(u32, 3), r.core().panes[id].?.file.?.scroll_row);
+ // A client joining over the view scrolled into the block has the row.
+ const late = try joinedNow(a, 2, 0);
+ defer late.deinit();
+ try agrees(a, late);
+ try std.testing.expectEqual(@as(u32, 3), late.core().panes[id].?.file.?.scroll_row);
+ // The client's view keys, each after the session drew (its geometry
+ // made for the frame; the client's is not): what a key reads of the
+ // body's rows is made of the state alone (the soak's divergence at a
+ // Ctrl-b, before File.shownRows laid the geometry out first).
+ var arena: std.heap.ArenaAllocator = .init(gpa);
+ defer arena.deinit();
+ for ([_]pardes.Key{ .{ .cp = 'b', .ctrl = true }, .{ .cp = 'f', .ctrl = true }, .{ .cp = 'd', .ctrl = true }, .{ .cp = 'u', .ctrl = true }, .{ .cp = 'e', .ctrl = true } }) |k| {
+ for (0..3) |_| {
+ {
+ const drew = Stepping.begin(&a.t, null);
+ defer drew.end();
+ _ = try a.core.render(arena.allocator());
+ }
+ const m = try gpa.dupe(u8, try r.input(.{ .key = k }));
+ defer gpa.free(m);
+ r.confirm(try a.take(m));
+ r.settle();
+ try agrees(a, r);
+ }
+ }
+ // A session's dump keeps the row.
+ const bytes = try pardes.dump.dumpBytes(a.core);
+ defer gpa.free(bytes);
+ const loaded = try pardes.dump.load(gpa, .{ .cols = 80, .rows = 24 }, bytes, null);
+ defer loaded.deinit();
+ try std.testing.expectEqual(walk.digest(Pardes, a.core), walk.digest(Pardes, loaded));
+ try std.testing.expectEqual(a.core.panes[id].?.file.?.scroll_row, loaded.panes[id].?.file.?.scroll_row);
+}
+
+test "a text's views under random orders of the session's and a client's keys, wheels and draws, keys of the session's between a client's and its confirm (rollbacks): every side agrees (an explorer of a view's rows)" {
+ const gpa = std.testing.allocator;
+ var text: std.ArrayList(u8) = .empty;
+ defer text.deinit(gpa);
+ // Lines of one row and of several (wrapped at 80 columns).
+ for (0..120) |i| if (i % 7 == 3) {
+ for (0..20 + i % 40) |w| try text.print(gpa, "w{d:0>3} ", .{w});
+ try text.append(gpa, '\n');
+ } else try text.print(gpa, "line {d}\n", .{i});
+ const keys = [_]pardes.Key{
+ .{ .cp = 'j', .text = "j" }, .{ .cp = 'k', .text = "k" },
+ .{ .cp = 'w', .text = "w" }, .{ .cp = 'b', .text = "b" },
+ .{ .cp = 'b', .ctrl = true }, .{ .cp = 'f', .ctrl = true },
+ .{ .cp = 'd', .ctrl = true }, .{ .cp = 'u', .ctrl = true },
+ .{ .cp = 'G', .text = "G" }, .{ .cp = 'z', .text = "z" },
+ .{ .cp = 't', .text = "t" }, .{ .cp = 'i', .text = "i" },
+ .{ .cp = 'x', .text = "x" }, .{ .cp = pardes.Key.escape },
+ .{ .cp = '/', .text = "/" }, .{ .cp = pardes.Key.enter },
+ };
+ for (0..view_orders) |seed| {
+ const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host());
+ defer a.deinit();
+ const was = Stepping.begin(&a.t, null);
+ _ = try a.core.setTestFile(text.items);
+ was.end();
+ _ = try a.unit(0, 0);
+ const id = a.core.view().active;
+ const r = try joinedNow(a, 1, 0);
+ defer r.deinit();
+ const opened = try a.openView(1);
+ r.view = opened.view;
+ r.confirm(opened.unit);
+ r.settle();
+ try agrees(a, r);
+ var prng: std.Random.DefaultPrng = .init(seed);
+ const rand = prng.random();
+ var arena: std.heap.ArenaAllocator = .init(gpa);
+ defer arena.deinit();
+ for (0..150) |_| {
+ const rect = a.core.views[r.view].?.rects[id];
+ const at = .{ .col = rect.x + 10, .row = rect.y + rect.h / 2 };
+ const ev: pardes.Event = switch (rand.uintLessThan(u8, 10)) {
+ 0 => .{ .mouse = .{ .button = .wheel_down, .kind = .press, .col = at.col, .row = at.row } },
+ 1 => .{ .mouse = .{ .button = .wheel_up, .kind = .press, .col = at.col, .row = at.row } },
+ else => .{ .key = keys[rand.uintLessThan(usize, keys.len)] },
+ };
+ if (rand.boolean()) {
+ const drew = Stepping.begin(&a.t, null);
+ defer drew.end();
+ _ = arena.reset(.retain_capacity);
+ _ = try a.core.render(arena.allocator());
+ }
+ if (rand.uintLessThan(u8, 4) == 0) _ = r.draw(.{ .ctx = null, .f = null });
+ if (rand.uintLessThan(u8, 3) == 0) {
+ // The session's own key, then nothing of the client's.
+ r.confirm(try a.local(.{ .key = keys[rand.uintLessThan(usize, keys.len)] }));
+ r.settle();
+ } else {
+ const m = try gpa.dupe(u8, try r.input(ev));
+ defer gpa.free(m);
+ // Sometimes the session's own key first: the client's
+ // applied at once is rolled back and replayed.
+ if (rand.uintLessThan(u8, 3) == 0) {
+ r.confirm(try a.local(.{ .key = keys[rand.uintLessThan(usize, keys.len)] }));
+ r.settle();
+ }
+ r.confirm(try a.take(m));
+ r.settle();
+ }
+ agrees(a, r) catch |err| {
+ std.debug.print("seed {d}: diverged\n", .{seed});
+ return err;
+ };
+ }
+ }
+}
+
/// Seeds of the explorer below a run of the suite takes; 3,000 were run
/// once (reports/pardes-term-join-10.md).
const view_orders = 30;