diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-09 03:29:30 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-09 03:30:49 -0300 |
| commit | 84c8209d02f6830db861c3a8dde0c710c88075f0 (patch) | |
| tree | 10f77e3ab1becb5a0af4de152bb8d8e0e9ee0f03 /src/File.zig | |
| parent | 446292e15d56c9c248dae5d6fde1be3a83ade82e (diff) | |
| download | pardes-84c8209d02f6830db861c3a8dde0c710c88075f0.tar.gz pardes-84c8209d02f6830db861c3a8dde0c710c88075f0.zip | |
idioms: the edit surface fails by name: the undo history (Journal.mark, Text.remember and step, File's, terminal's and edit's pushUndo and undoStep) returns error{OutOfMemory} instead of dropping an undo point, setEditText, enterInsert and insertTab return edit.Error with try where they reported each failure, Registers.put and setYank return error{OutOfMemory} instead of losing a yank, and their other-file callers decide (try under edit.Error, said on the pane by Undo, Redo, Pipe, Edit, Query, keys, look, completion, Incl and Plumb, ENOMEM or null where a 9P write answers, Ask's false); ctl.get and getFile return GetError (fs.ReadError, now named at fs.zig's surface, and InvalidName) for the *anyerror out-parameter and errno, the 9P get, Get and Edit's e mapping it as before; the OOM undo test pins the error; perf.zig's try relabels its harness hash, the three baselines re-keyed to it (their numbers the base's)
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/File.zig')
| -rw-r--r-- | src/File.zig | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/src/File.zig b/src/File.zig index 82661c6d..90711c9a 100644 --- a/src/File.zig +++ b/src/File.zig @@ -1245,20 +1245,20 @@ pub fn restoreSnap(pane: *Pane, f: *State, snap: Text.Place) void { /// An undo step's edge, made before an edit (Text.Journal.mark): the edits /// after it are one step back to the pane's place now. -pub fn pushUndo(p: *Pardes, pane: *Pane) void { +pub fn pushUndo(p: *Pardes, pane: *Pane) error{OutOfMemory}!void { const f = if (pane.file) |*file| file else return; - f.history.journal.mark(p.gpa, f.content, placeOf(pane, f)); + try f.history.journal.mark(p.gpa, f.content, placeOf(pane, f)); } /// Undo (back) or redo one step: its edits turned round in the text, and the /// place and name it began at (or, redone, was undone from) back. -pub fn undoStep(p: *Pardes, pane: *Pane, back: bool) void { +pub fn undoStep(p: *Pardes, pane: *Pane, back: bool) error{OutOfMemory}!void { const f = if (pane.file) |*file| file else return; const j = &f.history.journal; if (if (back) j.done == 0 else j.done == j.steps.items.len) return; const at = if (back) j.done - 1 else j.done; const now = placeOf(pane, f); - if (!turn(p, f, at, back)) return; + if (!turn(p, f, at, back)) return error.OutOfMemory; const s = &j.steps.items[at]; if (back) { s.after = now; @@ -1439,8 +1439,8 @@ pub fn changed(p: *Pardes, id: u8, bytes: []const u8) void { // Logged as the dirty case is, with what became of it. var rec: [32]u8 = undefined; pardes.ctlfs.events.notePath(p, "changed", std.fmt.bufPrint(&rec, "{d} reloaded", .{pane.serial}) catch unreachable); // a u32 fits 32 + pushUndo(p, pane) catch |err| return p.reportError(id, "reload", err); const new = p.gpa.dupe(u8, bytes) catch |err| return p.reportError(id, "reload", err); - pushUndo(p, pane); setContent(p, f, new); f.saved_revision = f.revision; restoreSnap(pane, f, .{ .cur_row = pane.body.cur_row, .cur_col = pane.body.cur_col, .vsel = pane.body.vsel }); @@ -2515,7 +2515,7 @@ test "undo and redo walk back and forth through every step of random edits, join for (0..80) |_| { const was = j.done; try texts.append(gpa, try gpa.dupe(u8, f.content)); - pushUndo(p, pane); + try pushUndo(p, pane); // A step that changed nothing goes on, its edge where it was. if (j.done == was) gpa.free(texts.pop().?); // Up to six edits: most where the last ended, as typing goes on. @@ -2535,11 +2535,11 @@ test "undo and redo walk back and forth through every step of random edits, join var k = texts.items.len - 1; while (k > 0) { k -= 1; - undoStep(p, pane, true); + try undoStep(p, pane, true); try std.testing.expectEqualStrings(texts.items[k], f.content); } for (texts.items[1..]) |t| { - undoStep(p, pane, false); + try undoStep(p, pane, false); try std.testing.expectEqualStrings(t, f.content); } } @@ -2559,42 +2559,42 @@ test "a text replaced whole keeps its old buffer for its undo, swapped back and defer for (texts) |t| gpa.free(t); setContent(p, f, try gpa.dupe(u8, texts[0])); const first = f.content.ptr; - pushUndo(p, pane); + try pushUndo(p, pane); setContent(p, f, try gpa.dupe(u8, texts[1])); // The old buffer itself, kept: no byte of it copied, none counted. const e = j.entries.items[j.entries.items.len - 1]; try std.testing.expect(e.swap and e.removed.ptr == first); try std.testing.expectEqual(@as(usize, @sizeOf(Text.Entry)), j.bytes); const second = f.content.ptr; - undoStep(p, pane, true); + try undoStep(p, pane, true); try std.testing.expect(f.content.ptr == first); try std.testing.expectEqualStrings(texts[0], f.content); - undoStep(p, pane, false); + try undoStep(p, pane, false); try std.testing.expect(f.content.ptr == second); try std.testing.expectEqualStrings(texts[1], f.content); // A third and a fourth: two swaps kept, the steps before them gone, said. for (texts[2..4]) |t| { - pushUndo(p, pane); + try pushUndo(p, pane); setContent(p, f, try gpa.dupe(u8, t)); } try std.testing.expectEqual(@as(usize, 2), j.done); try std.testing.expect(std.mem.indexOf(u8, pane.msg[0..pane.msg_len], "undo keeps the last two texts replaced whole") != null); - undoStep(p, pane, true); - undoStep(p, pane, true); + try undoStep(p, pane, true); + try undoStep(p, pane, true); try std.testing.expectEqualStrings(texts[1], f.content); - undoStep(p, pane, true); + try undoStep(p, pane, true); try std.testing.expectEqualStrings(texts[1], f.content); // A body emptied and written again on one open (a shell's >): its undo // swaps the old text back and folds the step into one swap the other way. - pushUndo(p, pane); + try pushUndo(p, pane); try std.testing.expect(replace(p, f, 0, f.content.len, "")); try std.testing.expect(replace(p, f, 0, 0, "fresh\n")); - undoStep(p, pane, true); + try undoStep(p, pane, true); try std.testing.expectEqualStrings(texts[1], f.content); try std.testing.expectEqual(@as(usize, 1), j.steps.items[j.done].n); - undoStep(p, pane, false); + try undoStep(p, pane, false); try std.testing.expectEqualStrings("fresh\n", f.content); - undoStep(p, pane, true); + try undoStep(p, pane, true); try std.testing.expectEqualStrings(texts[1], f.content); } @@ -2614,10 +2614,10 @@ test "undo keeps its steps within a byte bound, the newest always" { defer gpa.free(text); for (0..8) |i| { @memset(text, 'a' + @as(u8, @intCast(i))); - pushUndo(p, pane); + try pushUndo(p, pane); try std.testing.expect(replace(p, f, step / 2, step, text)); } - pushUndo(p, pane); + try pushUndo(p, pane); const j = &f.history.journal; try std.testing.expect(j.done > 0 and j.done < 8); try std.testing.expect(j.bytes <= limits.undo_bytes + step + @sizeOf(Text.Entry)); @@ -2627,11 +2627,11 @@ test "undo keeps its steps within a byte bound, the newest always" { sum += Text.Journal.held(e); } try std.testing.expectEqual(sum, j.bytes); - undoStep(p, pane, true); + try undoStep(p, pane, true); try std.testing.expectEqual(text[0], f.content[step / 2]); // Back as far as the bound kept: each step's middle whole again. while (j.done > 0) { - undoStep(p, pane, true); + try undoStep(p, pane, true); try std.testing.expect(std.mem.allEqual(u8, f.content[step / 2 ..][0..step], f.content[step / 2])); } } |
