diff options
| author | Gabriel Schneider <[email protected]> | 2026-10-02 01:01:43 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-02 01:33:55 -0300 |
| commit | 2537126c643db75419ff846f1041e40d154c9426 (patch) | |
| tree | d37ab2310b1dc41308c869afeb393608bfc5d245 | |
| parent | 39d4a7c38b12f907d8ba6c08bb14600b503a13d7 (diff) | |
| download | pardes-2537126c643db75419ff846f1041e40d154c9426.tar.gz pardes-2537126c643db75419ff846f1041e40d154c9426.zip | |
Insert on a terminal's text says it edits a copy, run with Tab or B2, that the program's next drawing replaces, and that Ctrl-b types to the program
Co-Authored-By: Claude Opus 5.5 <[email protected]>
| -rw-r--r-- | src/edit.zig | 12 | ||||
| -rw-r--r-- | src/terminal.zig | 5 | ||||
| -rw-r--r-- | test/snapshots/ttyedit.golden | 2 |
3 files changed, 19 insertions, 0 deletions
diff --git a/src/edit.zig b/src/edit.zig index bf65935e..b2909d87 100644 --- a/src/edit.zig +++ b/src/edit.zig @@ -2166,6 +2166,18 @@ test "Enter in insert mode keeps a tab-indented line's tabs, as o and O do" { try std.testing.expect(std.mem.startsWith(u8, pane.file.?.content, "\t\tvalue = 1;\n\t\t\n")); } +test "insert on a terminal's text says it edits a copy the program's next drawing replaces" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true }); + defer p.deinit(); + while (p.nextEffect()) |_| {} + const pane = p.panes[0].?; + if (!pane.isTerminal()) return error.SkipZigTest; + pane.body.mode = .normal; + p.update(.{ .key = .{ .cp = 'i' } }); + p.update(.{ .key = .{ .cp = 'x', .text = "x" } }); + try std.testing.expect(std.mem.indexOf(u8, pane.msg[0..pane.msg_len], "a copy of the terminal's text") != null); +} + test "insert and normal modes edit complete Unicode graphemes" { const gpa = std.testing.allocator; const p = try Pardes.init(gpa, .{ .cols = 60, .rows = 12 }); diff --git a/src/terminal.zig b/src/terminal.zig index 140dae76..3bb1fbda 100644 --- a/src/terminal.zig +++ b/src/terminal.zig @@ -1637,6 +1637,11 @@ pub fn editText(p: *Pardes, pane: *Pane, lo: i32, hi: i32, col: i32) ?EditText { if (pane.ovl) |overlay| p.gpa.free(overlay.text); pane.ovl = .{ .row = row0, .rows = covered, .text = text }; } + // A terminal's text is its program's: edited here it is a copy, to run + // with Tab or B2, gone when the program draws again. Said at its first + // edit, so it never looks like an edit that was lost. + if (fresh) for (p.panes, 0..) |slot, id| if (slot == pane) + p.setMessage(id, "a copy of the terminal's text: Tab or B2 runs it; what the program draws next replaces it (Ctrl-b types to the program)"); return .{ .text = pane.ovl.?.text, .row0 = pane.ovl.?.row }; } diff --git a/test/snapshots/ttyedit.golden b/test/snapshots/ttyedit.golden index ab1b1b5b..70ab8504 100644 --- a/test/snapshots/ttyedit.golden +++ b/test/snapshots/ttyedit.golden @@ -22,12 +22,14 @@ | words.txt == snap split grid=100x31 cursor=2,9 |2: ^ /tmp/pardes-snap/ttyedit/cwd Tty+bash Save Mode /tmp/pardes-snap/ttyedit/cwd Tty+bash Save Mode +|4: next replaces it (Ctrl-b types to the program) ls |8: one t |9: wo three |10: four five six |11: seven eight nine == snap opened grid=100x31 cursor=6,10 |2: /tmp/pardes-snap/ttyedit/cwd Tty+bash Save Mode /tmp/pardes-snap/ttyedit/cwd Tty+bash Save Mode +|4: ls ls |10: OPEN |11: four five six |12: seven eight nine |
