mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-15 08:16:13 +03:00
apprt/embedded: do not translate control characters
macOS translates inputs such as shift+tab into the control character tab (ascii 0x09). Linux/GTK does not translate character inputs except to printable characters. We don't want control character translations because these are all handled manually by our key encoder (i.e. translating ctrl+c to 0x03).
This commit is contained in:
@ -480,6 +480,13 @@ pub const Surface = struct {
|
||||
// If we aren't composing, then we set our preedit to
|
||||
// empty no matter what.
|
||||
self.core_surface.preeditCallback(null) catch {};
|
||||
|
||||
// If the text is just a single non-printable ASCII character
|
||||
// then we clear the text. We handle non-printables in the
|
||||
// key encoder manual (such as tab, ctrl+c, etc.)
|
||||
if (result.text.len == 1 and result.text[0] < 0x20) {
|
||||
break :translate .{ .composing = false, .text = "" };
|
||||
}
|
||||
}
|
||||
|
||||
break :translate result;
|
||||
|
@ -15,6 +15,8 @@ const KittyEntry = @import("kitty.zig").Entry;
|
||||
const kitty_entries = @import("kitty.zig").entries;
|
||||
const KittyFlags = terminal.kitty.KeyFlags;
|
||||
|
||||
const log = std.log.scoped(.key_encoder);
|
||||
|
||||
event: key.KeyEvent,
|
||||
|
||||
/// The state of various modes of a terminal that impact encoding.
|
||||
@ -29,6 +31,8 @@ pub fn encode(
|
||||
self: *const KeyEncoder,
|
||||
buf: []u8,
|
||||
) ![]const u8 {
|
||||
// log.debug("encode {}", .{self.*});
|
||||
|
||||
if (self.kitty_flags.int() != 0) return try self.kitty(buf);
|
||||
return try self.legacy(buf);
|
||||
}
|
||||
@ -863,6 +867,22 @@ test "kitty: up arrow with utf8" {
|
||||
try testing.expectEqualStrings("\x1b[A", actual);
|
||||
}
|
||||
|
||||
test "kitty: shift+tab" {
|
||||
var buf: [128]u8 = undefined;
|
||||
var enc: KeyEncoder = .{
|
||||
.event = .{
|
||||
.key = .tab,
|
||||
.mods = .{ .shift = true },
|
||||
.utf8 = "", // tab
|
||||
},
|
||||
|
||||
.kitty_flags = .{ .disambiguate = true, .report_alternates = true },
|
||||
};
|
||||
|
||||
const actual = try enc.kitty(&buf);
|
||||
try testing.expectEqualStrings("\x1b[9;2u", actual);
|
||||
}
|
||||
|
||||
test "legacy: ctrl+alt+c" {
|
||||
var buf: [128]u8 = undefined;
|
||||
var enc: KeyEncoder = .{
|
||||
|
Reference in New Issue
Block a user