summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-09-28 17:25:41 -0300
committerGabriel Schneider <[email protected]>2026-10-01 00:12:15 -0300
commitcf45be79a5ab96d3b81078e7e5e2ba58bd5e5cee (patch)
tree929851769f85a12da753d12f127789aa8a81b9e1 /src
parentc0302211818a95acb7a276abdba7a32eac2358d5 (diff)
downloadpardes-cf45be79a5ab96d3b81078e7e5e2ba58bd5e5cee.tar.gz
pardes-cf45be79a5ab96d3b81078e7e5e2ba58bd5e5cee.zip
Undo and Redo are builtins, as in acme's tags, so a pane's ctl and exec can step its body
Over 9P there was no way to take back an edit: acme's Undo and Redo were keys only. They are now pane builtins, reached from a tag, a pane ctl and exec, and listed in /commands. They are not added to the default tags, which would change every tag. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/builtins.zig14
-rw-r--r--src/config.zig2
-rw-r--r--src/ninep/ctl.zig15
3 files changed, 30 insertions, 1 deletions
diff --git a/src/builtins.zig b/src/builtins.zig
index 23d853c8..a755969b 100644
--- a/src/builtins.zig
+++ b/src/builtins.zig
@@ -850,6 +850,20 @@ pub const Togglettymode = struct {
}
};
+/// acme's Undo and Redo (exec.c `undo`): step the pane's body back or
+/// forward through its edits, from a tag, a pane ctl or exec.
+pub const Undo = struct {
+ pub fn run(c: Ctx) void {
+ edit.doUndo(c.p, &c.pane.body);
+ }
+};
+
+pub const Redo = struct {
+ pub fn run(c: Ctx) void {
+ edit.doRedo(c.p, &c.pane.body);
+ }
+};
+
/// Fold a pane to its tag, or restore its share of the column.
pub const Collapse = struct {
pub fn run(c: Ctx) void {
diff --git a/src/config.zig b/src/config.zig
index 186b29a1..416754a6 100644
--- a/src/config.zig
+++ b/src/config.zig
@@ -49,6 +49,8 @@ pub const leader_path = paths: {
.Mode = null,
.Togglettymode = null,
.Collapse = null,
+ .Undo = null,
+ .Redo = null,
.Repl = null,
.Kill = null,
.Exit = null,
diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig
index a64521e7..e4e983a8 100644
--- a/src/ninep/ctl.zig
+++ b/src/ninep/ctl.zig
@@ -542,10 +542,23 @@ test "commands lists every builtin with its argument and the ctl that takes it"
try testing.expect(words.next() == null);
}
try testing.expectEqual(std.enums.values(Builtin).len, lines);
- for ([_][]const u8{ "\nDel arg pane\n", "\nNewcol root\n", "\nSave arg pane\n", "\nVerbose arg root\n" }) |row|
+ for ([_][]const u8{ "\nDel arg pane\n", "\nNewcol root\n", "\nSave arg pane\n", "\nVerbose arg root\n", "\nUndo pane\n", "\nRedo pane\n" }) |row|
try testing.expect(std.mem.indexOf(u8, listed.bytes, row) != null);
}
+test "Undo and Redo on a pane's ctl step its body through its edits" {
+ const p = try withFile(testing.allocator, "one\n");
+ defer p.deinit();
+ const serial = serialOf(p);
+ const body = Node.of(serial, .body);
+ try testing.expectEqual(Status.ok, wr(p, body, "two\n").reply.status);
+ try testing.expectEqualStrings("one\ntwo\n", rd(p, body, 0, 64).bytes);
+ try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .ctl), "Undo").reply.status);
+ try testing.expectEqualStrings("one\n", rd(p, body, 0, 64).bytes);
+ try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .ctl), "Redo").reply.status);
+ try testing.expectEqualStrings("one\ntwo\n", rd(p, body, 0, 64).bytes);
+}
+
test "focus reads the pane with the keyboard, and a serial written to it moves the keyboard there" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();