From 4c635f357adb95235429d8905b8598a2643b4f3b Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Sat, 24 Oct 2026 13:55:12 -0300 Subject: drag 2/3: a pane's or column's grip let go past the window's edge opens it in a new window (Handover.zig) --- src/dump.zig | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'src/dump.zig') diff --git a/src/dump.zig b/src/dump.zig index 140bc476..0da2513f 100644 --- a/src/dump.zig +++ b/src/dump.zig @@ -283,6 +283,10 @@ pub const Column = struct { pub const Mount = struct { name: []const u8, dial: []const u8 }; +/// What a grip carried out of its window (Handover.zig): one pane with the +/// panes attached to it, or a whole column. A session's own dump is none. +pub const Carried = enum { pane, column }; + pub const State = struct { magic: []const u8 = magic, version: u32 = version, @@ -303,6 +307,8 @@ pub const State = struct { settings: []const []const u8 = &.{}, /// Incl's directories, in order; null in older dumps (the defaults). incl: ?[]const []const u8 = null, + /// A dump a grip carried to another window; null for a session's own. + carried: ?Carried = null, }; /// A header is a text like any other: it may hold newlines, but not a @@ -710,12 +716,24 @@ test "validation bounds pane restore state" { // ---- a whole editor to and from a dump (acme keeps this in rows.c) ---- pub fn dumpState(p: *Pardes) !void { + const bytes = try dumpBytes(p, null, null); + if (p.dump_out) |d| p.gpa.free(d); + p.dump_out = bytes; + p.emit(.write_dump); +} + +/// The dump of the panes `keep` marks (every pane for null), gpa-owned: a +/// whole session's, or what a grip carries to another window (Handover.zig), +/// `carried` saying which. Only the columns holding a kept pane are in it, +/// and a carried pane's column tag is its old column's no longer. +pub fn dumpBytes(p: *Pardes, keep: ?*const [MAX_PANES]bool, carried: ?Carried) ![]u8 { const arena = p.scratch.allocator(); var slot_to_pane: [MAX_PANES]?usize = @splat(null); var dump_panes: [MAX_PANES]Pane = undefined; var panes_len: usize = 0; for (p.panes, 0..) |slot, id| { const pane = slot orelse continue; + if (keep) |k| if (!k[id]) continue; slot_to_pane[id] = panes_len; dump_panes[panes_len] = try dumpPane(p, arena, pane); panes_len += 1; @@ -725,6 +743,7 @@ pub fn dumpState(p: *Pardes) !void { for (0..p.panes.len) |id| { const i = slot_to_pane[id] orelse continue; const owner = layout.ownerOf(p, id) orelse continue; + // An attachment carried without its owner stands on its own. dump_panes[i].attached_to = slot_to_pane[owner]; } // Zerox's twins: the text once, in the first; each other names it. @@ -753,9 +772,10 @@ pub fn dumpState(p: *Pardes) !void { column_ids[c][ids_len] = compact; ids_len += 1; }; + if (keep != null and ids_len == 0) continue; columns[columns_len] = .{ .serial = layout.columnSerial(p, c), - .tag = p.col_tags[c].own, + .tag = if (carried == .pane) null else p.col_tags[c].own, .weight = @as(f32, @floatFromInt(p.col_weight[c])) / @as(f32, @floatFromInt(column_weight_unit)), .panes = column_ids[c][0..ids_len], }; @@ -777,14 +797,13 @@ pub fn dumpState(p: *Pardes) !void { .mounts = mounts[0..p.fs.mounts.items.len], .settings = try changedSettings(p, arena), .incl = p.incl.items, + .carried = carried, }; try validate(state); var out: std.Io.Writer.Allocating = .init(p.gpa); errdefer out.deinit(); try std.zon.stringify.serialize(state, .{ .whitespace = true }, &out.writer); - if (p.dump_out) |d| p.gpa.free(d); - p.dump_out = try out.toOwnedSlice(); - p.emit(.write_dump); + return out.toOwnedSlice(); } /// One pane as a dump keeps it, its strings in `arena`: a Restore's, and a -- cgit v1.3