mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-17 01:06:08 +03:00
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:
@ -6,7 +6,13 @@ extension NSEvent {
|
||||
///
|
||||
/// This will not set the "text" or "composing" fields since these can't safely be set
|
||||
/// 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()
|
||||
key_ev.action = action
|
||||
key_ev.keycode = UInt32(keyCode)
|
||||
@ -22,7 +28,9 @@ extension NSEvent {
|
||||
// so far: control and command never contribute to the translation of text,
|
||||
// assume everything else did.
|
||||
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
|
||||
// ignore multi-codepoint values.
|
||||
|
@ -961,13 +961,19 @@ extension Ghostty {
|
||||
// These never have "composing" set to true because these are the
|
||||
// result of a composition.
|
||||
for text in list {
|
||||
_ = keyAction(action, event: translationEvent, text: text)
|
||||
_ = keyAction(
|
||||
action,
|
||||
event: event,
|
||||
translationEvent: translationEvent,
|
||||
text: text
|
||||
)
|
||||
}
|
||||
} else {
|
||||
// We have no accumulated text so this is a normal key event.
|
||||
_ = keyAction(
|
||||
action,
|
||||
event: translationEvent,
|
||||
event: event,
|
||||
translationEvent: translationEvent,
|
||||
text: translationEvent.ghosttyCharacters,
|
||||
composing: markedText.length > 0
|
||||
)
|
||||
@ -1165,12 +1171,13 @@ extension Ghostty {
|
||||
private func keyAction(
|
||||
_ action: ghostty_input_action_e,
|
||||
event: NSEvent,
|
||||
translationEvent: NSEvent? = nil,
|
||||
text: String? = nil,
|
||||
composing: Bool = false
|
||||
) -> Bool {
|
||||
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
|
||||
if let text {
|
||||
return text.withCString { ptr in
|
||||
|
Reference in New Issue
Block a user