summaryrefslogtreecommitdiff
path: root/core/jj.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/jj.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/jj.zig')
-rw-r--r--core/jj.zig173
1 files changed, 173 insertions, 0 deletions
diff --git a/core/jj.zig b/core/jj.zig
index 176ead49..c1d07662 100644
--- a/core/jj.zig
+++ b/core/jj.zig
@@ -3306,6 +3306,179 @@ test "a description is whole, its title and its author never cut: in a pane narr
}
}
+/// 60 numbered lines, line 20 of 130 numbered words (12 rows or more at
+/// 60 columns), and a change to line 40 whose title wraps over several
+/// rows: the rows a view scrolls through, the layer's description among
+/// them.
+const Tall = struct {
+ const title = "a title long enough to wrap: the description of this change says what it does and why at some length, " ++
+ "and then says it again in other words, and once more, so that no pane of sixty columns holds it in fewer than four rows " ++
+ "beside its author and its age";
+
+ fn repo(gpa: std.mem.Allocator) !?Repo {
+ var base: std.ArrayList(u8) = .empty;
+ defer base.deinit(gpa);
+ var changed: std.ArrayList(u8) = .empty;
+ defer changed.deinit(gpa);
+ for (0..60) |i| {
+ const from = base.items.len;
+ if (i == 20) {
+ for (0..130) |w| try base.print(gpa, "t{d:0>3} ", .{w});
+ try base.append(gpa, '\n');
+ } else try base.print(gpa, "line {d:0>2}\n", .{i});
+ try changed.appendSlice(gpa, if (i == 40) "line 40 changed\n" else base.items[from..]);
+ }
+ return Repo.with(gpa, &.{ .{ base.items, "base" }, .{ changed.items, title } }, null);
+ }
+
+ /// The buffer's line the description is.
+ fn description(f: *const File.State) !usize {
+ for (f.layer.lines) |l| if (std.mem.indexOf(u8, f.content[l.at..][0..l.len], title[0..20]) != null)
+ return std.mem.count(u8, f.content[0..l.at], "\n");
+ return error.NoDescription;
+ }
+
+ /// The rows of the text above line `line`'s row that shows its byte
+ /// `col`, in `pane`'s view.
+ fn rowsAbove(tab: u16, pane: *Pane, line: usize, col: usize) usize {
+ var n: usize = File.rowOf(tab, pane, line, col);
+ for (0..line) |l| n += File.lineRows(tab, pane, l);
+ return n;
+ }
+};
+
+test "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 wheel's notch is one row down the whole text and back, PageDown and PageUp a page of rows, zj and zk one; a held j and k keep the cursor's row three rows inside the body" {
+ const gpa = testing.allocator;
+ var repo = try Tall.repo(gpa) orelse return error.SkipZigTest;
+ defer repo.deinit(gpa);
+ const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 60, .rows = 24, .windowed = false });
+ defer p.deinit();
+ const tab = p.settings.tab;
+ var line: [4200]u8 = undefined;
+ p.update(.{ .command = try std.fmt.bufPrint(&line, "Look {s}", .{repo.file}) });
+ const id = p.view().active;
+ const pane = p.panes[id].?;
+ p.update(.{ .command = "Changes @-" });
+ p.sync();
+ const f = &pane.file.?;
+ try testing.expect(File.lineRows(tab, pane, 20) >= 12);
+ try testing.expect(File.lineRows(tab, pane, try Tall.description(f)) >= 4);
+ var total: usize = 0;
+ for (0..File.nlines(gpa, f)) |l| total += File.lineRows(tab, pane, l);
+ var arena: std.heap.ArenaAllocator = .init(gpa);
+ defer arena.deinit();
+ const shot = struct {
+ fn of(q: *Pardes, w: *Pane, a: std.mem.Allocator) ![]const []const u8 {
+ return Ghosts.rows(q, w, a, try a.alloc([]const u8, 256));
+ }
+ }.of;
+ const rect = p.view().rects[id];
+ const at = .{ .col = rect.x + 10, .row = p.bodyTop(pane, rect) + 5 };
+ const notch = struct {
+ fn of(down: bool, x: u16, y: u16) pardes.Event {
+ return .{ .mouse = .{ .button = if (down) .wheel_down else .wheel_up, .kind = .press, .col = x, .row = y } };
+ }
+ }.of;
+ // Every row of the text at the body's top in turn, a notch each: the
+ // body's rows one up.
+ var was = try shot(p, pane, arena.allocator());
+ const kept = was.len - 1;
+ var all: std.ArrayList([]const u8) = .empty;
+ try all.append(arena.allocator(), was[0]);
+ while (true) {
+ p.update(notch(true, at.col, at.row));
+ const now = try shot(p, pane, arena.allocator());
+ if (std.mem.eql(u8, now[0], was[0])) break;
+ for (now[0 .. kept - 1], was[1..kept]) |n, w| try testing.expectEqualStrings(w, n);
+ try all.append(arena.allocator(), now[0]);
+ was = now;
+ }
+ try testing.expectEqual(total, all.items.len);
+ // And back up, a row a notch.
+ var back = all.items.len - 1;
+ while (back > 0) : (back -= 1) {
+ p.update(notch(false, at.col, at.row));
+ const now = try shot(p, pane, arena.allocator());
+ try testing.expectEqualStrings(all.items[back - 1], now[0]);
+ for (now[1..kept], was[0 .. kept - 1]) |n, w| try testing.expectEqualStrings(w, n);
+ was = now;
+ }
+ const indexOf = struct {
+ fn in(rows: []const []const u8, row: []const u8) usize {
+ for (rows, 0..) |r, i| if (std.mem.eql(u8, r, row)) return i;
+ return rows.len;
+ }
+ }.in;
+ // PageDown and PageUp: a page of rows each, the text's last row at the
+ // top the furthest.
+ var top: usize = 0;
+ while (top < all.items.len - 1) {
+ p.update(.{ .key = .{ .cp = pardes.Key.page_down } });
+ top = @min(top + pane.rows, all.items.len - 1);
+ try testing.expectEqual(top, indexOf(all.items, (try shot(p, pane, arena.allocator()))[0]));
+ }
+ while (top > 0) {
+ p.update(.{ .key = .{ .cp = pardes.Key.page_up } });
+ top -|= pane.rows;
+ try testing.expectEqual(top, indexOf(all.items, (try shot(p, pane, arena.allocator()))[0]));
+ }
+ // zj and zk: a row each, through line 20's rows and the description's.
+ for (0..all.items.len - 1) |n| {
+ for ("zj") |k| p.update(.{ .key = .{ .cp = k, .text = &[_]u8{k} } });
+ try testing.expectEqual(n + 1, indexOf(all.items, (try shot(p, pane, arena.allocator()))[0]));
+ }
+ for (0..all.items.len - 1) |n| {
+ for ("zk") |k| p.update(.{ .key = .{ .cp = k, .text = &[_]u8{k} } });
+ try testing.expectEqual(all.items.len - 2 - n, indexOf(all.items, (try shot(p, pane, arena.allocator()))[0]));
+ }
+ // A held j from the first line to the last and a held k back: the
+ // cursor's row three rows (`scroll_off`) inside the body's edges, or
+ // as far as the text before or after it goes.
+ p.update(.{ .command = "Look a.zig:1" });
+ const body = File.shownRows(tab, pane);
+ for ("jk") |cp| for (0..total) |_| {
+ p.update(.{ .key = .{ .cp = cp, .text = &[_]u8{cp} } });
+ const t = File.top(tab, pane);
+ const cur = Tall.rowsAbove(tab, pane, @intCast(pane.body.cur_row), @intCast(pane.body.cur_col));
+ const on = cur - Tall.rowsAbove(tab, pane, t.line, 0) - t.row;
+ try testing.expect(on >= @min(pardes.config.scroll_off, cur));
+ try testing.expect(on <= body - 1 - @min(pardes.config.scroll_off, total - 1 - cur));
+ };
+}
+
+test "a client wheels its session's view a row a notch into a change's description wrapped over several rows (a line of the layer), agreeing with the session at every notch; a client joined over that view loads its row" {
+ var repo = try Tall.repo(testing.allocator) orelse return error.SkipZigTest;
+ defer repo.deinit(testing.allocator);
+ const R = pardes.replica;
+ const a = try R.Authority.init(testing.allocator, .{ .cols = 60, .rows = 24 }, .{});
+ defer a.deinit();
+ const r = try R.Replica.init(testing.allocator, 1, try a.unit(0, 0));
+ defer r.deinit();
+ var line: [4200]u8 = undefined;
+ r.confirm(try a.local(.{ .command = try std.fmt.bufPrint(&line, "Look {s}", .{repo.file}) }));
+ r.confirm(try a.local(.{ .command = "Changes @-" }));
+ r.settle();
+ const id = a.core.view().active;
+ const af = &a.core.panes[id].?.file.?;
+ const desc = try Tall.description(af);
+ 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 } };
+ var n: usize = 0;
+ while (af.scroll != desc or af.scroll_row != 2) : (n += 1) {
+ if (n > 300) return error.NeverThere;
+ const m = try testing.allocator.dupe(u8, try r.input(notch));
+ defer testing.allocator.free(m);
+ r.confirm(try a.take(m));
+ r.settle();
+ try testing.expect(r.diverged == null);
+ try testing.expectEqual(pardes.tape.digestOf(a.core), pardes.tape.digestOf(r.core()));
+ const rf = &r.core().panes[id].?.file.?;
+ try testing.expectEqual(af.scroll, rf.scroll);
+ try testing.expectEqual(af.scroll_row, rf.scroll_row);
+ }
+ try R.loadsAsSession(a, 2);
+}
+
test "at one place a change's ghost rows come before its description: a line it changed and the next it took away, then its description" {
const gpa = testing.allocator;
const fn_text = "fn f() void {\n a();\n b();\n c();\n d();\n}\n";