From 80de38271d0c53a194efde629612edc7b894ae52 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 29 Oct 2026 20:49:07 -0300 Subject: views: a view drawn while another is live keeps its selections, given back to its slot after the frame; a headless replica, which draws nothing, kept them and diverged (three-view monkey seeds 5 and 35) Co-Authored-By: Claude Opus 5.5 --- src/views.zig | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src/views.zig') diff --git a/src/views.zig b/src/views.zig index f40f77e5..bf9b9147 100644 --- a/src/views.zig +++ b/src/views.zig @@ -493,6 +493,18 @@ pub fn drawOthers(p: *Pardes, h: pardes.Host) !void { for (0..max) |i| { const k: u8 = @intCast(i); if (k == live or !isOpen(p, k)) continue; + // `unpark` hands each slot's selections to its body; drawn, the + // view is out again, and they are the slot's again (else a frame + // drawn would take them from a view, and a replica that draws + // nothing would keep them). + var sels: [MAX_PANES]struct { s: @TypeOf(@as(Pane, undefined).body.sels), n: @TypeOf(@as(Pane, undefined).body.nsel) } = undefined; + for (p.panes, 0..) |s, id| if (s) |pane| { + sels[id] = .{ .s = pane.pv[k].body.sels, .n = pane.pv[k].body.nsel }; + }; + defer for (p.panes, 0..) |s, id| if (s) |pane| { + pane.pv[k].body.sels = sels[id].s; + pane.pv[k].body.nsel = sels[id].n; + }; unpark(p, k); _ = p.frame_arena.reset(.{ .retain_with_limit = pardes.memory.limits.frame_kept }); const surface = try p.render(p.frame_arena.allocator()); @@ -692,6 +704,23 @@ test "drawing the other views leaves the live one as it was, to the digest" { try testing.expectEqual(@as(i32, 60), pane.body.cur_row); } +test "a view drawn while another is live keeps its own cursors" { + const gpa = testing.allocator; + const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 }); + defer p.deinit(); + const pane = try p.setTestFile("ab\ncd\nef\n"); + const k = p.openView().?; + p.toView(k); + p.update(.{ .key = .{ .cp = 'C', .text = "C" } }); + try testing.expectEqual(@as(u16, 1), pane.body.nsel); + p.toView(0); + const before = pardes.walk.digest(Pardes, p); + try drawOthers(p, .{}); + try testing.expectEqual(before, pardes.walk.digest(Pardes, p)); + p.toView(k); + try testing.expectEqual(@as(u16, 1), pane.body.nsel); +} + test "a view not live keeps its place in a text another view edits" { const gpa = testing.allocator; const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 }); -- cgit v1.3