From 4837d840f6a8d73ef9332542c919abe35f419f29 Mon Sep 17 00:00:00 2001 From: Gregory Anders Date: Wed, 27 Sep 2023 22:28:36 -0500 Subject: [PATCH] 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. --- macos/Sources/Ghostty/Ghostty.Input.swift | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/macos/Sources/Ghostty/Ghostty.Input.swift b/macos/Sources/Ghostty/Ghostty.Input.swift index 331fa087f..d49c284aa 100644 --- a/macos/Sources/Ghostty/Ghostty.Input.swift +++ b/macos/Sources/Ghostty/Ghostty.Input.swift @@ -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.