diff options
Diffstat (limited to 'core/mouse.zig')
| -rw-r--r-- | core/mouse.zig | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/core/mouse.zig b/core/mouse.zig index 6fb97787..5707cb57 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" { |
