fix: correctly handle vaxis.Key.multicodepoint in bracketed paste
closes #552
This commit is contained in:
parent
9a940eb7a4
commit
cfe6ba8c6b
2 changed files with 17 additions and 9 deletions
|
|
@ -172,6 +172,10 @@ pub fn ucs32_to_utf8(ucs32: []const u32, utf8: []u8) error{ Utf8CannotEncodeSurr
|
|||
return @intCast(try unicode.utf8Encode(@intCast(ucs32[0]), utf8));
|
||||
}
|
||||
|
||||
pub fn ucs32_to_utf8_scalar(ucs32: u32, utf8: []u8) error{ Utf8CannotEncodeSurrogateHalf, CodepointTooLarge }!usize {
|
||||
return @intCast(try unicode.utf8Encode(@intCast(ucs32), utf8));
|
||||
}
|
||||
|
||||
pub const utils = struct {
|
||||
pub fn key_id_string(k: Key) []const u8 {
|
||||
return switch (k) {
|
||||
|
|
|
|||
|
|
@ -428,20 +428,24 @@ fn handle_bracketed_paste_input(self: *Self, cbor_msg: []const u8) !bool {
|
|||
var keypress: input.Key = undefined;
|
||||
var egc_: input.Key = undefined;
|
||||
var mods: usize = undefined;
|
||||
var text: []const u8 = undefined;
|
||||
const writer = &self.bracketed_paste_buffer.writer;
|
||||
if (try cbor.match(cbor_msg, .{ "I", cbor.number, cbor.extract(&keypress), cbor.extract(&egc_), cbor.string, cbor.extract(&mods) })) {
|
||||
if (try cbor.match(cbor_msg, .{ "I", cbor.number, cbor.extract(&keypress), cbor.extract(&egc_), cbor.extract(&text), cbor.extract(&mods) })) {
|
||||
switch (keypress) {
|
||||
106 => if (mods == 4) try writer.writeAll("\n") else try writer.writeAll("j"),
|
||||
input.key.enter => try writer.writeAll("\n"),
|
||||
input.key.tab => try writer.writeAll("\t"),
|
||||
else => if (!input.is_non_input_key(keypress)) {
|
||||
var buf: [6]u8 = undefined;
|
||||
const bytes = try input.ucs32_to_utf8(&[_]u32{egc_}, &buf);
|
||||
try writer.writeAll(buf[0..bytes]);
|
||||
} else {
|
||||
var buf: [6]u8 = undefined;
|
||||
const bytes = try input.ucs32_to_utf8(&[_]u32{egc_}, &buf);
|
||||
self.logger.print("unexpected codepoint in paste: {d} {s}", .{ keypress, buf[0..bytes] });
|
||||
else => {
|
||||
if (keypress == vaxis.Key.multicodepoint) {
|
||||
try writer.writeAll(text);
|
||||
} else if (!input.is_non_input_key(keypress)) {
|
||||
var buf: [6]u8 = undefined;
|
||||
const bytes = try input.ucs32_to_utf8_scalar(egc_, &buf);
|
||||
try writer.writeAll(buf[0..bytes]);
|
||||
} else {
|
||||
var buf: [1024]u8 = undefined;
|
||||
self.logger.print("unexpected codepoint in paste event: {s}", .{cbor.toJson(cbor_msg, &buf) catch "cbor.toJson failed"});
|
||||
}
|
||||
},
|
||||
}
|
||||
return true;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue