From 137d24db9c7d6b44740bef6ced8120ce5fada76f Mon Sep 17 00:00:00 2001 From: Gregory Anders Date: Wed, 27 Sep 2023 22:30:27 -0500 Subject: [PATCH] macos: display keybinding instead of index in tab label --- .../Primary Window/PrimaryWindowManager.swift | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/macos/Sources/Features/Primary Window/PrimaryWindowManager.swift b/macos/Sources/Features/Primary Window/PrimaryWindowManager.swift index 6cc983931..6782084ca 100644 --- a/macos/Sources/Features/Primary Window/PrimaryWindowManager.swift +++ b/macos/Sources/Features/Primary Window/PrimaryWindowManager.swift @@ -184,17 +184,22 @@ class PrimaryWindowManager { /// shortcut that activates it (if any). This is called when the key window /// changes and when a window is closed. func relabelTabs() { - if let windows = self.mainWindow?.tabbedWindows { - for (index, window) in windows.enumerated().prefix(9) { - let string = " ⌘\(index + 1) " - let attributes: [NSAttributedString.Key: Any] = [ - .font: NSFont.labelFont(ofSize: 0), - .foregroundColor: window.isKeyWindow ? NSColor.labelColor : NSColor.secondaryLabelColor, - ] - let attributedString = NSAttributedString(string: string, attributes: attributes) - let text = NSTextField(labelWithAttributedString: attributedString) - window.tab.accessoryView = text + guard let windows = self.mainWindow?.tabbedWindows else { return } + guard let cfg = ghostty.config else { return } + 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 { + continue } + + let attributes: [NSAttributedString.Key: Any] = [ + .font: NSFont.labelFont(ofSize: 0), + .foregroundColor: window.isKeyWindow ? NSColor.labelColor : NSColor.secondaryLabelColor, + ] + let attributedString = NSAttributedString(string: " \(equiv) ", attributes: attributes) + let text = NSTextField(labelWithAttributedString: attributedString) + window.tab.accessoryView = text } } }