diff options
| -rw-r--r-- | core/Core.zig | 5 | ||||
| -rw-r--r-- | core/mouse.zig | 44 | ||||
| -rw-r--r-- | test/replicas.zig | 15 |
3 files changed, 54 insertions, 10 deletions
diff --git a/core/Core.zig b/core/Core.zig index b4745b24..360ba833 100644 --- a/core/Core.zig +++ b/core/Core.zig @@ -1594,6 +1594,10 @@ fn serveFsInner(p: *Pardes, req: ctlfs.Req) ctlfs.Reply { pub const update = pardes.tape.taped(updateInner); fn updateInner(p: *Pardes, ev: Event) void { const v = p.view(); + // Its bands as its state stands: a step reads them (a press on a chip, a + // body's top under them), and what a frame drew, a view put back or a + // dump left in Pane.notices (derived) is not what every core has. + for (p.panes, 0..) |slot, id| if (slot) |pane| Messages.collectNotices(p, pane, v.rects[id], id); defer pardes.panes.File.syncTwins(p); defer p.reportFocus(); // A tick with no deadline due is the one event that cannot change @@ -1812,6 +1816,7 @@ fn noteLateFailureInner(p: *Pardes, id: usize) void { pub const presented = pardes.tape.taped(presentedInner); fn presentedInner(p: *Pardes) void { const v = p.view(); + for (p.panes, 0..) |slot, id| if (slot) |pane| Messages.collectNotices(p, pane, v.rects[id], id); if (v.pointer_inside and v.drag != .none) { v.hover_col = v.pointer_raw_col; v.hover_row = v.pointer_raw_row; diff --git a/core/mouse.zig b/core/mouse.zig index 8e761453..150ea81c 100644 --- a/core/mouse.zig +++ b/core/mouse.zig @@ -1769,6 +1769,50 @@ test "a tag press is the same state whichever frame this process drew last" { try expectSame(two.a, two.b, "after the press"); } +// A notice band over a body's top rows is derived (Pane.notices): a frame +// writes it at its own time, so a step makes it again as its state stands +// before it reads it. Here the session draws a frame once Del's question is +// due (its band shown) and the replica none: a press on the band's chip is +// the same in both (the soak's divergence, through `kindMouse`, was this read). +test "a press on a notice's chip is the same state whichever frame this process drew last" { + const gpa = std.testing.allocator; + const a = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 40 }); + defer a.deinit(); + a.update(.{ .resize = .{ .cols = 80, .rows = 40, .row_metrics = test_metrics } }); + // Del asks which neighbour takes the rows of a pane with two. + a.newScratchBelow(a.view().active); + const mid = a.view().active; + a.newScratchBelow(mid); + a.view().active = mid; + a.sync(); + const bytes = try pardes.dump.dumpBytes(a); + defer gpa.free(bytes); + const b = try pardes.dump.load(gpa, a.opts, bytes, null); + defer b.deinit(); + for ([_]*Pardes{ a, b }) |p| { + p.clock.now_ns = 5 * std.time.ns_per_s; + p.clock.stepped_ns = p.clock.now_ns; + p.update(.{ .key = .{ .cp = ' ' } }); + p.update(.{ .key = .{ .cp = 'd' } }); + p.clock.now_ns = p.panes[mid].?.question_due_ns; + } + var frame: std.heap.ArenaAllocator = .init(gpa); + defer frame.deinit(); + _ = try a.render(frame.allocator()); + const pane = a.panes[mid].?; + try std.testing.expect(pane.notices.len > 0); + const last = pane.notices.len - 1; + try std.testing.expectEqual(Pane.Notices.Kind.prompt, pane.notices.kinds[last]); + const row = a.bodyTop(pane, a.view().rects[mid]) + pane.notices.row[last]; + const press: pardes.Event = .{ .mouse = .{ .button = .left, .kind = .press, .col = pane.notices.left[last] + 1, .row = row } }; + a.update(press); + b.update(press); + // What the press did (a pane's cwd and a message's wall-clock stamp + // differ between two cores in one test process: not compared). + try std.testing.expectEqual(a.view().drag, b.view().drag); + try std.testing.expectEqual(a.panes[mid].?.sel[0], b.panes[mid].?.sel[0]); +} + // The same through a body hit (edit.pointerTextSelection, a sweep's drag), // on a compact body layer (TreeContext), which a pixel shell inverts. test "a body press, drag and release are the same state whichever frame this process drew last" { diff --git a/test/replicas.zig b/test/replicas.zig index 7f7ca0b3..572707a9 100644 --- a/test/replicas.zig +++ b/test/replicas.zig @@ -792,19 +792,16 @@ const Soak = struct { /// A Peer's queue, swapped out as its writer swaps it (the Peers' /// allocator's). sending: std.ArrayListUnmanaged(u8) = .empty, - /// This wait ended at its frame's tick: its pump draws. - at_frame: bool = false, fn of(ctx: ?*anyopaque) *Soak { return @ptrCast(@alignCast(ctx.?)); } - /// Its own view drawn at its frame's tick (`.frame`), as the soak's - /// session always drew it; not after every pump, as a terminal's is: - /// drawn so, the soak finds a client's step replayed with a kind's call - /// more than the session's (reports/pardes-runners-d.md). - fn watchedHost(ctx: ?*anyopaque) bool { - return of(ctx).at_frame; + /// Its own view drawn after every pump, as a terminal's session draws + /// its own (Core.render: drawn whenever a frame is owed and someone + /// sees it, and a terminal is always seen). + fn watchedHost(_: ?*anyopaque) bool { + return true; } fn ptyWrite(ctx: ?*anyopaque, pane: u8, bytes: []const u8) void { @@ -1124,7 +1121,6 @@ const Soak = struct { return false; } var took_output = false; - s.at_frame = false; // What its boundary took is old news. _ = s.l.peers.urgent.swap(false, .acq_rel); while (true) { @@ -1219,7 +1215,6 @@ const Soak = struct { s.frames_left = if (busy) 120 else s.frames_left -| 1; if (s.frames_left > 0) try net.send(.{ .at = m.at + frame_us, .n = 0, .kind = .frame, .who = 0, .bytes = &.{} }); if (took_output or core.needs_frame or (core.nextWake() orelse std.math.maxInt(u64)) <= s.now_ns) { - s.at_frame = true; s.framed = true; s.encode_ns = s.l.peers.screens.encode_ns; return false; |
