diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-25 07:03:02 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-25 07:03:03 -0300 |
| commit | eb8ecb8a451ae32d590c42755614b801f9cc0c09 (patch) | |
| tree | 0ea2f19acf06694ed744061b6ba41541ab0f2ae9 | |
| parent | 6068e48aa4cec242dc0c29865b06347573fdd1ae (diff) | |
| download | pardes-eb8ecb8a451ae32d590c42755614b801f9cc0c09.tar.gz pardes-eb8ecb8a451ae32d590c42755614b801f9cc0c09.zip | |
views, dump, draw: a load makes each view's band rows again from its own tag state, and the tag's own rows are held to MAX_TAG_ROWS where the frame reads them (the coordinator's item from P3's soak: `index out of bounds: index 15, len 8` at draw.zig paintPaneTag, `for (lines[0..rows])`, from views.drawOne in a replica client's draw after a divergence); RUN FIRST: views.zig's new test on the parent, its band-rows check left out: `panic: index out of bounds: index 12, len 8` at draw.zig:1007 paintPaneTag, from joinPaneTag, renderPane, render, drawOne: the same fault; THE CAUSE: a tag's `tag_rows` counts its band's rows (Core.sync: the band unrolled under its text pushes the body down) and is dumped and in the digest, while `band_rows` is derived (views.PaneView and Pane: never dumped, made again at every sync); a load (a join's dump, a replica's rollback) zeroed `band_rows` and kept `tag_rows`, so a view drawn before its next step (drawOne: a replica client's own view, a pump's other views; no sync there) read the tag's own rows as `tag_rows - band_rows` = the band's too, 12 to 19, and indexed paintPaneTag's `[MAX_TAG_ROWS]` array past its 8; THE FIX: views.bandsLoaded (from dump.afterLoad, after TagState.loaded) makes each open view's `band_rows` again within that view from its own state as its sync does (`Band.takes`, 0 for a folded pane and Band.over's), into the pane's live field and the view's share (derived: the digest is unchanged, as the test checks); draw.joinPaneTag and paintPaneTag hold the tag's own rows to MAX_TAG_ROWS (`-|` and `@min`): production code never panics on a stale pair; TEST: views.zig "a view not live with its band open, dumped and loaded, draws before its next step: its band's rows made again from its state, its tag's rows never past MAX_TAG_ROWS" (SPC Down in view 0, another view live, byteDump, load: the digest equal, view 0's share's band rows 11 again (0 on the parent), drawOne draws it; with its band rows zeroed by hand drawOne draws it too); a user's client could abort on a join or a rollback while another view had a band open; core-test 1073/1244 (171 skipped)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE
| -rw-r--r-- | core/draw.zig | 7 | ||||
| -rw-r--r-- | core/dump.zig | 1 | ||||
| -rw-r--r-- | core/views.zig | 48 |
3 files changed, 53 insertions, 3 deletions
diff --git a/core/draw.zig b/core/draw.zig index 28b9f22d..2ef72f0e 100644 --- a/core/draw.zig +++ b/core/draw.zig @@ -822,8 +822,9 @@ fn joinPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r const chrome = p.chromeTheme(); const region = s.region(.tag, id).?; const tag = (try tagline.shownTag(p, arena, pane)).text; - // The tag's text rows; the band's under them are its own layer. - const rows = pane.tag_rows - pane.band_rows; + // The tag's text rows; the band's under them are its own layer. A + // tag's own are MAX_TAG_ROWS at most (Pardes.sync). + const rows = @min(pane.tag_rows -| pane.band_rows, MAX_TAG_ROWS); // As wide as the widest row it shows, and never narrower than its // viewport. var widest: usize = 0; @@ -978,7 +979,7 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, const tx = r.x + @min(TAG_TEXT_INSET, r.w); const tw = r.w -| TAG_TEXT_INSET; const tag_y = p.tagTop(pane, r); - const rows = pane.tag_rows - pane.band_rows; + const rows = @min(pane.tag_rows -| pane.band_rows, MAX_TAG_ROWS); const page_rgb = th.bg orelse th.tag_bg; // Focus is visible along the tag without changing its live text grid. const tag_bg = tagGround(p, pane, active); diff --git a/core/dump.zig b/core/dump.zig index 2dde9c8c..c0403c06 100644 --- a/core/dump.zig +++ b/core/dump.zig @@ -149,6 +149,7 @@ fn afterLoad(p: *Pardes) void { }; @import("jj.zig").loaded(p); pardes.TagState.loaded(p); + pardes.views.bandsLoaded(p); } /// A file kept slim in a dump (`dumpExit`, a closed pane's past its bound, diff --git a/core/views.zig b/core/views.zig index b05a116b..7bf30aa0 100644 --- a/core/views.zig +++ b/core/views.zig @@ -171,6 +171,24 @@ pub fn undumped(p: *Pardes, others: []const Shares) void { } } +/// After a load: each view's band rows (derived: never dumped nor in the +/// digest) made again from its own tag state as its last sync made them. +/// Its tag rows, which are dumped, count them, and a view drawn before its +/// next step (drawOne: a replica client's, a pump's other views) reads the +/// tag's own rows as their difference (draw.zig): with the band's rows +/// zeroed by the load, a band's became the tag's, past MAX_TAG_ROWS. +pub fn bandsLoaded(p: *Pardes) void { + for (0..max) |k| if (isOpen(p, @intCast(k))) within(p, @intCast(k), {}, bandsOf) catch {}; +} + +fn bandsOf(_: void, p: *Pardes) anyerror!void { + for (p.panes, 0..) |slot, id| if (slot) |pane| { + const rows = if (pane.collapsed or pardes.Band.over(pane)) 0 else @min(pardes.Band.takes(p, id), pane.tag_rows -| 1); + pane.band_rows = rows; + pane.pv[p.live].band_rows = rows; + }; +} + /// The views a dump before `Pardes.views` kept (`OldDumped`): each its /// share of the session into `views[k]`, the rest as `undumped`. What /// each view holds is the session's then; one refused is freed. @@ -581,6 +599,36 @@ pub fn within(p: *Pardes, k: u8, ctx: anytype, comptime f: fn (@TypeOf(ctx), *Pa const testing = std.testing; const Key = pardes.Key; +test "a view not live with its band open, dumped and loaded, draws before its next step: its band's rows made again from its state, its tag's rows never past MAX_TAG_ROWS" { + const gpa = std.testing.allocator; + const dump = @import("dump.zig"); + const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 30 }); + defer p.deinit(); + const pane = try p.setTestFile("one\n"); + // SPC's level unrolled in view 0: its band's rows in the tag's. + p.update(.{ .key = .{ .cp = ' ' } }); + p.update(.{ .key = .{ .cp = Key.down } }); + p.sync(); + const band = pane.band_rows; + try testing.expect(band > 0 and pane.tag_rows - band <= pardes.MAX_TAG_ROWS and pane.tag_rows > pardes.MAX_TAG_ROWS); + // Another view live, view 0 parked, as a client's is when a join's + // (a replica's rollback's) dump is made. + const k = p.openView().?; + p.toView(k); + const bytes = try dump.byteDump(p); + defer gpa.free(bytes); + const q = try dump.load(gpa, .{ .tty_only = true, .cols = 80, .rows = 30 }, bytes, null); + defer q.deinit(); + try testing.expectEqual(pardes.walk.digest(Pardes, p), pardes.walk.digest(Pardes, q)); + // View 0 drawn with no step first (a client's draw, a pump's other + // views): its band as it was, the tag's own rows under the bound. + try testing.expectEqual(band, q.panes[0].?.pv[0].band_rows); + _ = try drawOne(q, 0, .{ .ctx = null, .f = null }); + // The bound itself: a share whose band's rows are not counted. + q.panes[0].?.pv[0].band_rows = 0; + _ = try drawOne(q, 0, .{ .ctx = null, .f = null }); +} + fn typeKeys(p: *Pardes, text: []const u8) void { for (text) |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } }); } |
