summaryrefslogtreecommitdiff
path: root/src/views.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-29 20:49:07 -0300
committerGabriel Schneider <[email protected]>2026-10-29 21:13:33 -0300
commit80de38271d0c53a194efde629612edc7b894ae52 (patch)
tree6ccd3f18c0f482867a44379897d13a834254cbb6 /src/views.zig
parent62ff3eed83c1970921f6550b2a02c9ac89bc5205 (diff)
downloadpardes-80de38271d0c53a194efde629612edc7b894ae52.tar.gz
pardes-80de38271d0c53a194efde629612edc7b894ae52.zip
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 <[email protected]>
Diffstat (limited to 'src/views.zig')
-rw-r--r--src/views.zig29
1 files changed, 29 insertions, 0 deletions
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 });