summaryrefslogtreecommitdiff
path: root/src/layout.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/layout.zig')
-rw-r--r--src/layout.zig22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/layout.zig b/src/layout.zig
index 1c43bbd4..f789ba02 100644
--- a/src/layout.zig
+++ b/src/layout.zig
@@ -30,6 +30,7 @@ pub const Presentation = struct {
pending: bool = false,
previous_cells: []pardes.Cell = &.{},
previous_body_layers: [MAX_PANES]pardes.BodyLayer = @splat(.{}),
+ previous_tag_layers: [pardes.MAX_TAG_LAYERS]pardes.TagLayer = @splat(.{}),
previous_cols: u16 = 0,
previous_rows: u16 = 0,
previous_valid: bool = false,
@@ -42,6 +43,7 @@ pub const Presentation = struct {
pub fn deinit(self: *Presentation, gpa: std.mem.Allocator) void {
if (self.previous_cells.len > 0) gpa.free(self.previous_cells);
for (&self.previous_body_layers) |*layer| gpa.free(layer.cells);
+ for (&self.previous_tag_layers) |*layer| gpa.free(layer.cells);
if (self.diffs.len > 0) gpa.free(self.diffs);
}
@@ -312,6 +314,17 @@ pub const Presentation = struct {
old.* = current.*;
old.cells = storage;
}
+ for (&self.previous_tag_layers, surface.tagLayers()) |*old, *current| {
+ const count = if (current.cols > 0) current.cells.len else 0;
+ const storage = if (old.cells.len == count) old.cells else gpa.realloc(old.cells, count) catch {
+ self.previous_valid = false;
+ self.previous_layout = @splat(null);
+ return;
+ };
+ if (count > 0) @memcpy(storage, current.cells);
+ old.* = current.*;
+ old.cells = storage;
+ }
@memcpy(self.previous_cells, cells);
self.previous_cols = surface.cols;
self.previous_rows = surface.rows;
@@ -550,6 +563,7 @@ pub const Presentation = struct {
if (self.diff_state == .ready) {
s.previous_cells = self.previous_cells;
s.previous_body_layers = &self.previous_body_layers;
+ s.previous_tag_layers = &self.previous_tag_layers;
s.cell_diffs = self.diffs;
}
s.npanel_tracks = paintOrder(
@@ -2103,7 +2117,7 @@ test "fractional panel inverse preserves compact header rows through slide and z
}
}
-test "presentation snapshots own compact body rows across later edits" {
+test "presentation snapshots own compact body and tag rows across later edits" {
var state: Presentation = .{};
defer state.deinit(std.testing.allocator);
var cells: [1]pardes.Cell = .{.{}};
@@ -2111,12 +2125,18 @@ test "presentation snapshots own compact body rows across later edits" {
body[0].text[0] = 'A';
var surface: pardes.Surface = .{ .cols = 1, .rows = 1, .cells = &cells };
surface.body_layers[0] = .{ .serial = 9, .cols = 1, .rows = 2, .context_rows = 1, .cells = &body };
+ var tag: [1]pardes.Cell = .{.{}};
+ tag[0].text[0] = 'T';
+ surface.tag_layers[0] = .{ .kind = .pane, .serial = 9, .cols = 1, .cells = &tag };
state.capturePrevious(std.testing.allocator, &surface);
try std.testing.expect(state.previous_valid);
+ tag[0].text[0] = 'U';
+ try std.testing.expectEqual(@as(u8, 'T'), state.previous_tag_layers[0].cells[0].text[0]);
body[0].text[0] = 'B';
surface.body_layers[0].context_rows = 0;
try std.testing.expectEqual(@as(u8, 'A'), state.previous_body_layers[0].cells[0].text[0]);
try std.testing.expectEqual(@as(u16, 1), state.previous_body_layers[0].context_rows);
state.capturePrevious(std.testing.allocator, &surface);
try std.testing.expectEqual(@as(u8, 'B'), state.previous_body_layers[0].cells[0].text[0]);
+ try std.testing.expectEqual(@as(u8, 'U'), state.previous_tag_layers[0].cells[0].text[0]);
}