macos: create modifier flags as OptionSet instead of from array

Nit picky change, but the OptionSet class (which NSEvent.ModifierFlags
is an instance of) has an API for incrementally setting values without
needing to create an array.
This commit is contained in:
Gregory Anders
2023-09-27 22:28:36 -05:00
committed by Mitchell Hashimoto
parent 8f75e83958
commit 4837d840f6

View File

@ -9,12 +9,12 @@ extension Ghostty {
/// Returns the event modifier flags set for the Ghostty mods enum.
static func eventModifierFlags(mods: ghostty_input_mods_e) -> NSEvent.ModifierFlags {
var flags: [NSEvent.ModifierFlags] = [];
if (mods.rawValue & GHOSTTY_MODS_SHIFT.rawValue != 0) { flags.append(.shift) }
if (mods.rawValue & GHOSTTY_MODS_CTRL.rawValue != 0) { flags.append(.control) }
if (mods.rawValue & GHOSTTY_MODS_ALT.rawValue != 0) { flags.append(.option) }
if (mods.rawValue & GHOSTTY_MODS_SUPER.rawValue != 0) { flags.append(.command) }
return NSEvent.ModifierFlags(flags)
var flags = NSEvent.ModifierFlags(rawValue: 0);
if (mods.rawValue & GHOSTTY_MODS_SHIFT.rawValue != 0) { flags.insert(.shift) }
if (mods.rawValue & GHOSTTY_MODS_CTRL.rawValue != 0) { flags.insert(.control) }
if (mods.rawValue & GHOSTTY_MODS_ALT.rawValue != 0) { flags.insert(.option) }
if (mods.rawValue & GHOSTTY_MODS_SUPER.rawValue != 0) { flags.insert(.command) }
return flags
}
/// A map from the Ghostty key enum to the keyEquivalent string for shortcuts.