mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-09-14 18:01:58 +00:00
Translate printable physical keybindings through the current macOS keyboard layout before assigning menu key equivalents. Previously these bindings could not be represented because SwiftUI shortcuts are character-based, so actions such as super+backquote had no native menu shortcut. Keep native keycodes as dispatch identity so translated display characters do not change physical semantics or precedence over Unicode bindings. Refresh shortcuts when the input source changes, and prevent AppKit from transforming equivalents that are already localized.
38 lines
1.1 KiB
Swift
38 lines
1.1 KiB
Swift
import AppKit
|
|
import Testing
|
|
@testable import Ghostty
|
|
|
|
@MainActor
|
|
struct KeyboardLayoutTests {
|
|
@Test(arguments: [
|
|
0x00, // W3C KeyA
|
|
0x12, // W3C Digit1
|
|
0x32, // W3C Backquote
|
|
])
|
|
func characterHandlesKeyCode(keyCode: UInt16) {
|
|
#expect(KeyboardLayout.character(for: keyCode, modifiers: []) != nil)
|
|
}
|
|
|
|
@Test func characterRejectsInvalidKeyCode() {
|
|
#expect(KeyboardLayout.character(for: UInt16.max, modifiers: []) == nil)
|
|
}
|
|
|
|
@Test(arguments: [
|
|
([.shift, .control, .option], []),
|
|
([.command, .shift, .control, .option], .command),
|
|
] as [(NSEvent.ModifierFlags, NSEvent.ModifierFlags)])
|
|
func characterUsesOnlyCommandModifier(
|
|
modifiers: NSEvent.ModifierFlags,
|
|
effectiveModifiers: NSEvent.ModifierFlags
|
|
) throws {
|
|
let keyCode: UInt16 = 0x00 // W3C KeyA
|
|
let expected = try #require(KeyboardLayout.character(
|
|
for: keyCode,
|
|
modifiers: effectiveModifiers))
|
|
let actual = try #require(KeyboardLayout.character(
|
|
for: keyCode,
|
|
modifiers: modifiers))
|
|
#expect(actual == expected)
|
|
}
|
|
}
|