macos: display keybinding instead of index in tab label

This commit is contained in:
Gregory Anders
2023-09-27 22:30:27 -05:00
committed by Mitchell Hashimoto
parent 1fbd5e5590
commit 137d24db9c

View File

@ -184,17 +184,22 @@ class PrimaryWindowManager {
/// shortcut that activates it (if any). This is called when the key window /// shortcut that activates it (if any). This is called when the key window
/// changes and when a window is closed. /// changes and when a window is closed.
func relabelTabs() { func relabelTabs() {
if let windows = self.mainWindow?.tabbedWindows { guard let windows = self.mainWindow?.tabbedWindows else { return }
for (index, window) in windows.enumerated().prefix(9) { guard let cfg = ghostty.config else { return }
let string = "\(index + 1) " for (index, window) in windows.enumerated().prefix(9) {
let attributes: [NSAttributedString.Key: Any] = [ let action = "goto_tab:\(index + 1)"
.font: NSFont.labelFont(ofSize: 0), let trigger = ghostty_config_trigger(cfg, action, UInt(action.count))
.foregroundColor: window.isKeyWindow ? NSColor.labelColor : NSColor.secondaryLabelColor, guard let equiv = Ghostty.keyEquivalent(key: trigger.key, mods: trigger.mods) else {
] continue
let attributedString = NSAttributedString(string: string, attributes: attributes)
let text = NSTextField(labelWithAttributedString: attributedString)
window.tab.accessoryView = text
} }
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
} }
} }
} }