From 0e4b91de88bd78302043ec5d2ed17ebb7465bd56 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 28 Sep 2023 08:34:27 -0700 Subject: [PATCH] macos: stylistic changes --- .../Primary Window/PrimaryWindowManager.swift | 2 +- macos/Sources/Ghostty/Ghostty.Input.swift | 25 +++++++------------ 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/macos/Sources/Features/Primary Window/PrimaryWindowManager.swift b/macos/Sources/Features/Primary Window/PrimaryWindowManager.swift index 6782084ca..249b624c9 100644 --- a/macos/Sources/Features/Primary Window/PrimaryWindowManager.swift +++ b/macos/Sources/Features/Primary Window/PrimaryWindowManager.swift @@ -189,7 +189,7 @@ class PrimaryWindowManager { for (index, window) in windows.enumerated().prefix(9) { let action = "goto_tab:\(index + 1)" let trigger = ghostty_config_trigger(cfg, action, UInt(action.count)) - guard let equiv = Ghostty.keyEquivalent(key: trigger.key, mods: trigger.mods) else { + guard let equiv = Ghostty.keyEquivalentLabel(key: trigger.key, mods: trigger.mods) else { continue } diff --git a/macos/Sources/Ghostty/Ghostty.Input.swift b/macos/Sources/Ghostty/Ghostty.Input.swift index af0bc4d55..1655b80ad 100644 --- a/macos/Sources/Ghostty/Ghostty.Input.swift +++ b/macos/Sources/Ghostty/Ghostty.Input.swift @@ -7,24 +7,17 @@ extension Ghostty { return Self.keyToEquivalent[key] } - static func keyEquivalent(key: ghostty_input_key_e, mods: ghostty_input_mods_e) -> String? { + /// Returns the keyEquivalent label that includes the mods. + static func keyEquivalentLabel(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)" - } + + // Note: the order below matters; it matches the ordering modifiers show for + // macOS menu shortcut labels. + 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 }