From d815a5cc854b3cd14a89f401565db212c3dc9d88 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 5 Nov 2026 11:26:35 -0300 Subject: text journal, the ring and undo over it: a file's undo is the journal of its edits (Text.Journal: entries of an offset, the bytes taken out and the count put in, grouped in steps between marks, each step with the place it began at and the place it was undone from), bounded at 256 steps or 64 MiB, the newest kept; pushUndo marks a step (none when the last changed nothing, as a snapshot equal to the text was none) and every edit goes into the last step, joined to its last entry when they touch (typing on, backspace over it, a write going on where the last ended); undo and redo turn a step's entries round, one in place, several in a copy whose gap moves from one to the next (File.Gap), one edit and one revision as the snapshot's was; the snapshots go (File.Snapshot, the undo and redo arrays and their copies of the whole text at every step); the replica's copy pins an entry's bytes (Entry.removed, a blob) as it pinned a snapshot's; tests: 'undo keeps its steps within a byte bound, the newest always' reads the journal, 'file history owns bounded snapshot storage without per-edit bookkeeping allocations' becomes 'file history keeps its last undo_max steps, and an undo or redo with no memory changes nothing', the far join's blob test makes its two blobs beside the text with a delete and a yank (its history held whole texts before), and the counts of steps read history.journal.done Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/Pipe.zig | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/Pipe.zig') diff --git a/src/Pipe.zig b/src/Pipe.zig index 1f0ee5fc..3045d738 100644 --- a/src/Pipe.zig +++ b/src/Pipe.zig @@ -446,7 +446,7 @@ test "selection pipe replaces all ranges atomically and undo restores them" { const outputs: []const []const u8 = &.{ "AA\n", "" }; p.update(.{ .pipe_resp = .{ .id = id, .success = true, .outputs = outputs } }); try std.testing.expectEqualSlices(u8, "AA bb \n", pane.file.?.content); - try std.testing.expectEqual(@as(usize, 1), pane.file.?.history.undo_len); + try std.testing.expectEqual(@as(usize, 1), pane.file.?.history.journal.done); try std.testing.expectEqual(@as(u16, 1), pane.body.nsel); try std.testing.expectEqual(@as(i32, 1), pane.body.cur_col); try std.testing.expectEqual(@as(i32, 6), pane.body.sels[0].col); @@ -514,7 +514,7 @@ test "a command with no stdin runs once and every cursor gets that one answer" { p.update(.{ .pipe_resp = .{ .id = id, .success = true, .outputs = &.{"T"} } }); try std.testing.expectEqualSlices(u8, "Taa bb Tcc\n", pane.file.?.content); - try std.testing.expectEqual(@as(usize, 1), pane.file.?.history.undo_len); + try std.testing.expectEqual(@as(usize, 1), pane.file.?.history.journal.done); } test "selection pipe failure and stale completion never mutate the file" { @@ -532,7 +532,7 @@ test "selection pipe failure and stale completion never mutate the file" { const failed_id = nextPipeEffect(p) orelse return error.MissingPipeEffect; p.update(.{ .pipe_resp = .{ .id = failed_id, .success = false, .outputs = &.{} } }); try std.testing.expectEqualSlices(u8, "abc\n", pane.file.?.content); - try std.testing.expectEqual(@as(usize, 0), pane.file.?.history.undo_len); + try std.testing.expectEqual(@as(usize, 0), pane.file.?.history.journal.done); p.update(.{ .key = .{ .cp = '|' } }); p.update(.{ .key = .{ .cp = 'c', .text = "cat" } }); @@ -541,7 +541,7 @@ test "selection pipe failure and stale completion never mutate the file" { panes.File.setContent(p, &pane.file.?, try gpa.dupe(u8, "changed\n")); p.update(.{ .pipe_resp = .{ .id = stale_id, .success = true, .outputs = &.{"ABC"} } }); try std.testing.expectEqualSlices(u8, "changed\n", pane.file.?.content); - try std.testing.expectEqual(@as(usize, 0), pane.file.?.history.undo_len); + try std.testing.expectEqual(@as(usize, 0), pane.file.?.history.journal.done); } test "a failed filter opens an errors buffer carrying the command's own words" { @@ -570,7 +570,7 @@ test "a failed filter opens an errors buffer carrying the command's own words" { // The text is untouched — a failed filter is not an edit... try std.testing.expectEqualSlices(u8, "abc\n", pane.file.?.content); - try std.testing.expectEqual(@as(usize, 0), pane.file.?.history.undo_len); + try std.testing.expectEqual(@as(usize, 0), pane.file.?.history.journal.done); // ...and the cursor did not go anywhere, so `|` again edits the same file. try std.testing.expectEqual(@as(usize, 0), p.active); @@ -603,7 +603,7 @@ test "selection pipe rejects a reused pane slot and a superseded request" { pane = try p.setTestFile("new\n"); // same slot, different serial p.update(.{ .pipe_resp = .{ .id = replaced_id, .success = true, .outputs = &.{"OLD"} } }); try std.testing.expectEqualSlices(u8, "new\n", pane.file.?.content); - try std.testing.expectEqual(@as(usize, 0), pane.file.?.history.undo_len); + try std.testing.expectEqual(@as(usize, 0), pane.file.?.history.journal.done); pane.body.cur_col = 2; pane.body.vsel = .{ .active = true, .row = 0, .col = 0, .explicit = true }; @@ -621,7 +621,7 @@ test "selection pipe rejects a reused pane slot and a superseded request" { try std.testing.expectEqualSlices(u8, "new\n", pane.file.?.content); p.update(.{ .pipe_resp = .{ .id = latest_id, .success = true, .outputs = &.{"NEW"} } }); try std.testing.expectEqualSlices(u8, "NEW\n", pane.file.?.content); - try std.testing.expectEqual(@as(usize, 1), pane.file.?.history.undo_len); + try std.testing.expectEqual(@as(usize, 1), pane.file.?.history.journal.done); } test "selection pipe binding is file-normal-only" { -- cgit v1.3