From 1fbd5e5590e7413db52b253decbfb98964351004 Mon Sep 17 00:00:00 2001 From: Gregory Anders Date: Wed, 27 Sep 2023 22:30:10 -0500 Subject: [PATCH] macos: add keyEquivalent overload to also return modifier string --- macos/Sources/Ghostty/Ghostty.Input.swift | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/macos/Sources/Ghostty/Ghostty.Input.swift b/macos/Sources/Ghostty/Ghostty.Input.swift index d49c284aa..af0bc4d55 100644 --- a/macos/Sources/Ghostty/Ghostty.Input.swift +++ b/macos/Sources/Ghostty/Ghostty.Input.swift @@ -7,6 +7,28 @@ extension Ghostty { return Self.keyToEquivalent[key] } + static func keyEquivalent(key: ghostty_input_key_e, mods: ghostty_input_mods_e) -> String? { + guard var key = Self.keyEquivalent(key: key) else { return nil } + let flags = Self.eventModifierFlags(mods: mods) + if flags.contains(.command) { + key = "⌘\(key)" + } + + if flags.contains(.shift) { + key = "⇧\(key)" + } + + if flags.contains(.option) { + key = "⌥\(key)" + } + + if flags.contains(.control) { + key = "⌃\(key)" + } + + return key + } + /// 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(rawValue: 0);