summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/terminal.zig15
-rw-r--r--test/panes.zig16
2 files changed, 26 insertions, 5 deletions
diff --git a/src/terminal.zig b/src/terminal.zig
index 5338afa7..16ffb34b 100644
--- a/src/terminal.zig
+++ b/src/terminal.zig
@@ -1616,9 +1616,14 @@ pub fn forwardKey(p: *Pardes, id: usize, key: Key) void {
utf8[0 .. std.unicode.utf8Encode(text_cp, &utf8) catch return]
else
"";
- var buffer: [256]u8 = undefined;
- var writer = std.Io.Writer.fixed(&buffer);
- input.encodeKey(&writer, .{
+ // A key's text has no bound of its own (an input method's commit, a
+ // paste as one key): past the stack's room the encoding grows on the
+ // heap, and emitWrite cuts it into writes.
+ var room: [256]u8 = undefined;
+ var first: std.heap.BufferFirstAllocator = .init(&room, p.gpa);
+ var out: std.Io.Writer.Allocating = .init(first.allocator());
+ defer out.deinit();
+ input.encodeKey(&out.writer, .{
.key = physical,
.mods = .{ .ctrl = key.ctrl, .alt = key.alt, .shift = key.shift },
.consumed_mods = .{ .shift = key.text.len > 0 and key.shift },
@@ -1637,8 +1642,8 @@ pub fn forwardKey(p: *Pardes, id: usize, key: Key) void {
// the floor and forwards Alt-n to the child as a bare `n`.
opts.macos_option_as_alt = .true;
break :options opts;
- }) catch return;
- if (writer.end > 0) p.emit(.{ .write = .{ .pane = @intCast(id), .bytes = .from(writer.buffered()) } });
+ }) catch |err| return p.reportError(id, "key", err);
+ if (out.written().len > 0) p.emitWrite(id, out.written());
}
pub fn enterTty(p: *Pardes, id: usize) void {
diff --git a/test/panes.zig b/test/panes.zig
index 55ad303d..f221499b 100644
--- a/test/panes.zig
+++ b/test/panes.zig
@@ -2580,6 +2580,22 @@ const TerminalTests = struct {
}
}
+ test "a raw terminal key whose text passes one write goes whole, in writes in order" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true });
+ defer p.deinit();
+ while (p.nextEffect()) |_| {}
+ // A paste delivered as one key's text (an input method's commit).
+ const text: []const u8 = &@as([1000]u8, @splat('x'));
+ forwardKey(p, 0, .{ .cp = 'p', .text = text });
+ var got: std.ArrayList(u8) = .empty;
+ defer got.deinit(std.testing.allocator);
+ while (p.nextEffect()) |effect| switch (effect) {
+ .write => |write| try got.appendSlice(std.testing.allocator, write.bytes.slice()),
+ else => return error.UnexpectedEffect,
+ };
+ try std.testing.expectEqualStrings(text, got.items);
+ }
+
test "an edit buffer slides shell rows and their colors together" {
const testing = std.testing;
const p = try Pardes.init(testing.allocator, .{ .startup_config = "Theme helix\n", .tty_only = true, .cols = 18, .rows = 12 });