diff options
| -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} } }); } |
