macos: add the active terminals to our command palette to jump
parent
e1e782c617
commit
835fe3dd0f
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue