Skip to content
Closed
34 changes: 34 additions & 0 deletions Resources/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -83424,6 +83424,40 @@
}
}
},
"shortcut.key.pageUp": {
"extractionState": "manual",
"localizations": {
"en": {
"stringUnit": {
"state": "translated",
"value": "Page Up"
}
},
"ja": {
"stringUnit": {
"state": "translated",
"value": "ページアップ"
}
}
}
},
"shortcut.key.pageDown": {
"extractionState": "manual",
"localizations": {
"en": {
"stringUnit": {
"state": "translated",
"value": "Page Down"
}
},
"ja": {
"stringUnit": {
"state": "translated",
"value": "ページダウン"
}
}
}
},
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
"shortcut.pressShortcut.prompt": {
"extractionState": "manual",
"localizations": {
Expand Down
74 changes: 68 additions & 6 deletions Sources/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,8 @@ final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCent
private var ghosttyGotoSplitRightShortcut: StoredShortcut?
private var ghosttyGotoSplitUpShortcut: StoredShortcut?
private var ghosttyGotoSplitDownShortcut: StoredShortcut?
private var ghosttyPreviousTabShortcut: StoredShortcut?
private var ghosttyNextTabShortcut: StoredShortcut?
private var browserAddressBarFocusedPanelId: UUID?
private var browserOmnibarRepeatStartWorkItem: DispatchWorkItem?
private var browserOmnibarRepeatTickWorkItem: DispatchWorkItem?
Expand Down Expand Up @@ -1147,7 +1149,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCent
titlebarAccessoryController.start()
windowDecorationsController.start()
installMainWindowKeyObserver()
refreshGhosttyGotoSplitShortcuts()
refreshGhosttyNavigationShortcuts()
installGhosttyConfigObserver()
installWindowResponderSwizzles()
installBrowserAddressBarFocusObservers()
Expand Down Expand Up @@ -10527,7 +10529,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCent
object: nil,
queue: .main
) { [weak self] _ in
self?.refreshGhosttyGotoSplitShortcuts()
self?.refreshGhosttyNavigationShortcuts()
}
}

Expand All @@ -10544,12 +10546,14 @@ final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCent
#endif
}

private func refreshGhosttyGotoSplitShortcuts() {
private func refreshGhosttyNavigationShortcuts() {
guard let config = GhosttyApp.shared.config else {
ghosttyGotoSplitLeftShortcut = nil
ghosttyGotoSplitRightShortcut = nil
ghosttyGotoSplitUpShortcut = nil
ghosttyGotoSplitDownShortcut = nil
ghosttyPreviousTabShortcut = nil
ghosttyNextTabShortcut = nil
return
}

Expand All @@ -10565,6 +10569,12 @@ final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCent
ghosttyGotoSplitDownShortcut = storedShortcutFromGhosttyTrigger(
ghostty_config_trigger(config, "goto_split:down", UInt("goto_split:down".utf8.count))
)
ghosttyPreviousTabShortcut = storedShortcutFromGhosttyTrigger(
ghostty_config_trigger(config, "previous_tab", UInt("previous_tab".utf8.count))
)
ghosttyNextTabShortcut = storedShortcutFromGhosttyTrigger(
ghostty_config_trigger(config, "next_tab", UInt("next_tab".utf8.count))
)
}

private func storedShortcutFromGhosttyTrigger(_ trigger: ghostty_input_trigger_s) -> StoredShortcut? {
Expand All @@ -10580,6 +10590,10 @@ final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCent
key = "↑"
case GHOSTTY_KEY_ARROW_DOWN:
key = "↓"
case GHOSTTY_KEY_PAGE_UP:
key = "pageUp"
case GHOSTTY_KEY_PAGE_DOWN:
key = "pageDown"
case GHOSTTY_KEY_A: key = "a"
case GHOSTTY_KEY_B: key = "b"
case GHOSTTY_KEY_C: key = "c"
Expand Down Expand Up @@ -10650,7 +10664,28 @@ final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCent
return nil
}

return StoredShortcut(key: key, command: command, shift: shift, option: option, control: control)
let keyCode: UInt16?
if trigger.tag == GHOSTTY_TRIGGER_PHYSICAL {
switch trigger.key.physical {
case GHOSTTY_KEY_PAGE_UP:
keyCode = 116
case GHOSTTY_KEY_PAGE_DOWN:
keyCode = 121
default:
keyCode = nil
}
} else {
keyCode = nil
}

return StoredShortcut(
key: key,
command: command,
shift: shift,
option: option,
control: control,
keyCode: keyCode
)
}

private func handleQuitShortcutWarning() -> Bool {
Expand Down Expand Up @@ -11333,7 +11368,12 @@ final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCent
}

// Workspace navigation: Cmd+Ctrl+] / Cmd+Ctrl+[
if matchConfiguredShortcut(event: event, action: .nextSidebarTab) {
if matchConfiguredShortcut(event: event, action: .nextSidebarTab) ||
shouldRouteGhosttyTabNavigationShortcut(
event: event,
shortcut: ghosttyNextTabShortcut,
preservingCmuxSurfaceAction: .nextSurface
) {
#if DEBUG
let selected = tabManager?.selectedTabId.map { String($0.uuidString.prefix(5)) } ?? "nil"
cmuxDebugLog(
Expand All @@ -11344,7 +11384,12 @@ final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCent
return true
}

if matchConfiguredShortcut(event: event, action: .prevSidebarTab) {
if matchConfiguredShortcut(event: event, action: .prevSidebarTab) ||
shouldRouteGhosttyTabNavigationShortcut(
event: event,
shortcut: ghosttyPreviousTabShortcut,
preservingCmuxSurfaceAction: .prevSurface
) {
#if DEBUG
let selected = tabManager?.selectedTabId.map { String($0.uuidString.prefix(5)) } ?? "nil"
cmuxDebugLog(
Expand Down Expand Up @@ -12622,6 +12667,23 @@ final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCent
return matchConfiguredShortcut(event: event, shortcut: KeyboardShortcutSettings.shortcut(for: action))
}

private func shouldRouteGhosttyTabNavigationShortcut(
event: NSEvent,
shortcut: StoredShortcut?,
preservingCmuxSurfaceAction surfaceAction: KeyboardShortcutSettings.Action
) -> Bool {
guard let shortcut,
matchShortcut(event: event, shortcut: shortcut) else {
return false
}

// Ghostty's macOS defaults use Cmd+Shift+[/] for previous/next tab,
// which cmux owns as surface navigation. Keep cmux's active surface
// shortcut authoritative, while allowing user Ghostty tab bindings
// such as Cmd+Option+Arrow or Ctrl+PageUp/PageDown to drive workspaces.
return !matchConfiguredShortcut(event: event, action: surfaceAction)
}

fileprivate func shouldForwardBrowserSurfaceShortcutToTerminal(_ event: NSEvent) -> Bool {
return KeyboardShortcutSettings.Action.allCases.contains {
$0.shortcutContext == .browserPanel &&
Expand Down
19 changes: 18 additions & 1 deletion Sources/KeyboardShortcutSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,10 @@ struct ShortcutStroke: Equatable, Hashable {
case "\t":
return String(localized: "shortcut.key.tab", defaultValue: "Tab")
case "space": return String(localized: "shortcut.key.space", defaultValue: "Space")
case "pageUp", "pageup":
return String(localized: "shortcut.key.pageUp", defaultValue: "Page Up")
case "pageDown", "pagedown":
return String(localized: "shortcut.key.pageDown", defaultValue: "Page Down")
case "\r":
return "↩"
case "media.brightnessDown":
Expand Down Expand Up @@ -1490,6 +1494,8 @@ struct ShortcutStroke: Equatable, Hashable {
case 126: return "↑" // up arrow
case 48: return "\t" // tab
case 49: return "space" // kVK_Space
case 116: return "pageUp" // kVK_PageUp
case 121: return "pageDown" // kVK_PageDown
case 36, 76: return "\r" // return, keypad enter
case 33: return "[" // kVK_ANSI_LeftBracket
case 30: return "]" // kVK_ANSI_RightBracket
Expand Down Expand Up @@ -1658,6 +1664,8 @@ struct ShortcutStroke: Equatable, Hashable {
case "media.next": return 17
case "media.previous": return 18
case "space": return 49
case "pageup": return 116
case "pagedown": return 121
case "a": return 0
case "s": return 1
case "d": return 2
Expand Down Expand Up @@ -1717,7 +1725,12 @@ struct ShortcutStroke: Equatable, Hashable {
}

private static func usesDirectKeyCodeMatching(_ key: String) -> Bool {
key == "space" || functionKeyDisplayString(for: key) != nil || key.hasPrefix("media.")
let normalized = key.lowercased()
return normalized == "space" ||
normalized == "pageup" ||
normalized == "pagedown" ||
functionKeyDisplayString(for: normalized) != nil ||
normalized.hasPrefix("media.")
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
}

private static func functionKeyDisplayString(for key: String) -> String? {
Expand Down Expand Up @@ -2096,6 +2109,10 @@ extension ShortcutStroke {
return "\r"
case "space", "spacebar", "<space>":
return "space"
case "pageup", "page_up", "page-up", "<pageup>":
return "pageUp"
case "pagedown", "page_down", "page-down", "<pagedown>":
return "pageDown"
case "comma":
return ","
case "period", "dot":
Expand Down
Loading
Loading