macos: add the active terminals to our command palette to jump

pull/9945/head
Mitchell Hashimoto 2025-12-17 09:17:09 -08:00
parent e1e782c617
commit 835fe3dd0f
No known key found for this signature in database
GPG Key ID: 523D5DC389D273BC
3 changed files with 44 additions and 3 deletions

View File

@ -64,6 +64,7 @@ struct TerminalCommandPaletteView: View {
private var commandOptions: [CommandOption] {
var options: [CommandOption] = []
options.append(contentsOf: updateOptions)
options.append(contentsOf: jumpOptions)
options.append(contentsOf: terminalOptions)
return options
}
@ -122,6 +123,34 @@ struct TerminalCommandPaletteView: View {
return []
}
}
/// Commands for jumping to other terminal surfaces.
private var jumpOptions: [CommandOption] {
TerminalController.all.flatMap { controller -> [CommandOption] in
guard let window = controller.window else { return [] }
let color = (window as? TerminalWindow)?.tabColor
let displayColor = color != TerminalTabColor.none ? color : nil
return controller.surfaceTree.map { surface in
let title = surface.title.isEmpty ? window.title : surface.title
let displayTitle = title.isEmpty ? "Untitled" : title
return CommandOption(
title: "Focus: \(displayTitle)",
description: surface.pwd?.abbreviatedPath,
leadingIcon: "rectangle.on.rectangle",
leadingColor: displayColor?.displayColor.map { Color($0) }
) {
NotificationCenter.default.post(
name: Ghostty.Notification.ghosttyPresentTerminal,
object: surface
)
}
}
}
}
}
/// This is done to ensure that the given view is in the responder chain.

View File

@ -709,9 +709,12 @@ class BaseTerminalController: NSWindowController,
guard let target = notification.object as? Ghostty.SurfaceView else { return }
guard surfaceTree.contains(target) else { return }
// Bring the window to front and focus the surface without activating the app
window?.orderFrontRegardless()
Ghostty.moveFocus(to: target)
// Bring the window to front and focus the surface.
window?.makeKeyAndOrderFront(nil)
// We use a small delay to ensure this runs after any UI cleanup
// (e.g., command palette restoring focus to its original surface).
Ghostty.moveFocus(to: target, delay: 0.1)
}
// MARK: Local Events

View File

@ -17,4 +17,13 @@ extension String {
return url
}
#endif
/// Returns the path with the home directory abbreviated as ~.
var abbreviatedPath: String {
let home = FileManager.default.homeDirectoryForCurrentUser.path
if hasPrefix(home) {
return "~" + dropFirst(home.count)
}
return self
}
}