macos: translationMods should be used for consumed mods calculation

Fixes #7131
Regression from #7121

Our consumed mods should not include "alt" if `macos-option-as-alt` is
set. To do this, we need to calculate our consumed mods based on the
actual translation event mods (if available, only available during
keyDown).
This commit is contained in:
Mitchell Hashimoto
2025-04-18 14:25:34 -07:00
parent 65356c25da
commit edb8616341
2 changed files with 20 additions and 5 deletions

View File

@ -6,7 +6,13 @@ extension NSEvent {
/// ///
/// This will not set the "text" or "composing" fields since these can't safely be set /// This will not set the "text" or "composing" fields since these can't safely be set
/// with the information or lifetimes given. /// with the information or lifetimes given.
func ghosttyKeyEvent(_ action: ghostty_input_action_e) -> ghostty_input_key_s { ///
/// The translationMods should be set to the modifiers used for actual character
/// translation if available.
func ghosttyKeyEvent(
_ action: ghostty_input_action_e,
translationMods: NSEvent.ModifierFlags? = nil,
) -> ghostty_input_key_s {
var key_ev: ghostty_input_key_s = .init() var key_ev: ghostty_input_key_s = .init()
key_ev.action = action key_ev.action = action
key_ev.keycode = UInt32(keyCode) key_ev.keycode = UInt32(keyCode)
@ -22,7 +28,9 @@ extension NSEvent {
// so far: control and command never contribute to the translation of text, // so far: control and command never contribute to the translation of text,
// assume everything else did. // assume everything else did.
key_ev.mods = Ghostty.ghosttyMods(modifierFlags) key_ev.mods = Ghostty.ghosttyMods(modifierFlags)
key_ev.consumed_mods = Ghostty.ghosttyMods(modifierFlags.subtracting([.control, .command])) key_ev.consumed_mods = Ghostty.ghosttyMods(
(translationMods ?? modifierFlags)
.subtracting([.control, .command]))
// Our unshifted codepoint is the codepoint with no modifiers. We // Our unshifted codepoint is the codepoint with no modifiers. We
// ignore multi-codepoint values. // ignore multi-codepoint values.

View File

@ -961,13 +961,19 @@ extension Ghostty {
// These never have "composing" set to true because these are the // These never have "composing" set to true because these are the
// result of a composition. // result of a composition.
for text in list { for text in list {
_ = keyAction(action, event: translationEvent, text: text) _ = keyAction(
action,
event: event,
translationEvent: translationEvent,
text: text
)
} }
} else { } else {
// We have no accumulated text so this is a normal key event. // We have no accumulated text so this is a normal key event.
_ = keyAction( _ = keyAction(
action, action,
event: translationEvent, event: event,
translationEvent: translationEvent,
text: translationEvent.ghosttyCharacters, text: translationEvent.ghosttyCharacters,
composing: markedText.length > 0 composing: markedText.length > 0
) )
@ -1165,12 +1171,13 @@ extension Ghostty {
private func keyAction( private func keyAction(
_ action: ghostty_input_action_e, _ action: ghostty_input_action_e,
event: NSEvent, event: NSEvent,
translationEvent: NSEvent? = nil,
text: String? = nil, text: String? = nil,
composing: Bool = false composing: Bool = false
) -> Bool { ) -> Bool {
guard let surface = self.surface else { return false } guard let surface = self.surface else { return false }
var key_ev = event.ghosttyKeyEvent(action) var key_ev = event.ghosttyKeyEvent(action, translationMods: translationEvent?.modifierFlags)
key_ev.composing = composing key_ev.composing = composing
if let text { if let text {
return text.withCString { ptr in return text.withCString { ptr in