macOS: translation mods should never have "control"

This also lets us get rid of our `C-/` special handling to prevent a
system beep.
pull/7132/head
Mitchell Hashimoto 2025-04-18 15:07:27 -07:00
parent edb8616341
commit 18d6faf597
No known key found for this signature in database
GPG Key ID: 523D5DC389D273BC
3 changed files with 25 additions and 23 deletions

View File

@ -11,7 +11,7 @@ extension NSEvent {
/// translation if available.
func ghosttyKeyEvent(
_ action: ghostty_input_action_e,
translationMods: NSEvent.ModifierFlags? = nil,
translationMods: NSEvent.ModifierFlags? = nil
) -> ghostty_input_key_s {
var key_ev: ghostty_input_key_s = .init()
key_ev.action = action

View File

@ -1046,16 +1046,6 @@ extension Ghostty {
let equivalent: String
switch (event.charactersIgnoringModifiers) {
case "/":
// Treat C-/ as C-_. We do this because C-/ makes macOS make a beep
// sound and we don't like the beep sound.
if (!event.modifierFlags.contains(.control) ||
!event.modifierFlags.isDisjoint(with: [.shift, .command, .option])) {
return false
}
equivalent = "_"
case "\r":
// Pass C-<return> through verbatim
// (prevent the default context menu equivalent)

View File

@ -150,21 +150,25 @@ pub const Mods = packed struct(Mods.Backing) {
/// like macos-option-as-alt. The translation mods should be used for
/// translation but never sent back in for the key callback.
pub fn translation(self: Mods, option_as_alt: config.OptionAsAlt) Mods {
// We currently only process macos-option-as-alt so other
// platforms don't need to do anything.
if (comptime !builtin.target.os.tag.isDarwin()) return self;
var result = self;
// Control is never used for translation.
result.ctrl = false;
// macos-option-as-alt for darwin
if (comptime builtin.target.os.tag.isDarwin()) alt: {
// Alt has to be set only on the correct side
switch (option_as_alt) {
.false => return self,
.false => break :alt,
.true => {},
.left => if (self.sides.alt == .right) return self,
.right => if (self.sides.alt == .left) return self,
.left => if (self.sides.alt == .right) break :alt,
.right => if (self.sides.alt == .left) break :alt,
}
// Unset alt
var result = self;
result.alt = false;
}
return result;
}
@ -186,6 +190,14 @@ pub const Mods = packed struct(Mods.Backing) {
);
}
test "translation removes control" {
const testing = std.testing;
const mods: Mods = .{ .ctrl = true };
const result = mods.translation(.true);
try testing.expectEqual(Mods{}, result);
}
test "translation macos-option-as-alt" {
if (comptime !builtin.target.os.tag.isDarwin()) return error.SkipZigTest;