mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-10-01 23:48:35 +00:00
macos: do not send UTF-8 PUA codepoints to key events
Fixes #7337 AppKit encodes functional keys as PUA codepoints. We don't want to send that down as valid text encoding for a key event because KKP uses that in particular to change the encoding with associated text. I think there may be a more specific solution to this by only doing this within the KKP encoding part of KeyEncoder but that was filled with edge cases and I didn't want to risk breaking anything else.
This commit is contained in:
@@ -56,13 +56,20 @@ extension NSEvent {
|
||||
// If we have no characters associated with this event we do nothing.
|
||||
guard let characters else { return nil }
|
||||
|
||||
// If we have a single control character, then we return the characters
|
||||
// without control pressed. We do this because we handle control character
|
||||
// encoding directly within Ghostty's KeyEncoder.
|
||||
if characters.count == 1,
|
||||
let scalar = characters.unicodeScalars.first,
|
||||
scalar.value < 0x20 {
|
||||
return self.characters(byApplyingModifiers: modifierFlags.subtracting(.control))
|
||||
let scalar = characters.unicodeScalars.first {
|
||||
// If we have a single control character, then we return the characters
|
||||
// without control pressed. We do this because we handle control character
|
||||
// encoding directly within Ghostty's KeyEncoder.
|
||||
if scalar.value < 0x20 {
|
||||
return self.characters(byApplyingModifiers: modifierFlags.subtracting(.control))
|
||||
}
|
||||
|
||||
// If we have a single value in the PUA, then it's a function key and
|
||||
// we don't want to send PUA ranges down to Ghostty.
|
||||
if scalar.value >= 0xF700 && scalar.value <= 0xF8FF {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
return characters
|
||||
|
Reference in New Issue
Block a user