macos: enter and shift+enter move the results

pull/9709/head
Mitchell Hashimoto 2025-11-25 17:25:01 -08:00
parent efc05523e0
commit cfbc219f5c
No known key found for this signature in database
GPG Key ID: 523D5DC389D273BC
2 changed files with 43 additions and 16 deletions

View File

@ -412,14 +412,17 @@ extension Ghostty {
.background(Color.primary.opacity(0.1))
.cornerRadius(6)
.focused($isSearchFieldFocused)
.onSubmit {
guard let surface = surfaceView.surface else { return }
let action = "navigate_search:next"
ghostty_surface_binding_action(surface, action, UInt(action.count))
}
.onExitCommand {
Ghostty.moveFocus(to: surfaceView)
}
.backport.onKeyPress(.return) { modifiers in
guard let surface = surfaceView.surface else { return .ignored }
let action = modifiers.contains(.shift)
? "navigate_search:previous"
: "navigate_search:next"
ghostty_surface_binding_action(surface, action, UInt(action.count))
return .handled
}
Button(action: {
guard let surface = surfaceView.surface else { return }

View File

@ -18,6 +18,12 @@ extension Backport where Content: Scene {
// None currently
}
/// Result type for backported onKeyPress handler
enum BackportKeyPressResult {
case handled
case ignored
}
extension Backport where Content: View {
func pointerVisibility(_ v: BackportVisibility) -> some View {
#if canImport(AppKit)
@ -42,6 +48,24 @@ extension Backport where Content: View {
return content
#endif
}
/// Backported onKeyPress that works on macOS 14+ and is a no-op on macOS 13.
func onKeyPress(_ key: KeyEquivalent, action: @escaping (EventModifiers) -> BackportKeyPressResult) -> some View {
#if canImport(AppKit)
if #available(macOS 14, *) {
return content.onKeyPress(key, phases: .down, action: { keyPress in
switch action(keyPress.modifiers) {
case .handled: return .handled
case .ignored: return .ignored
}
})
} else {
return content
}
#else
return content
#endif
}
}
enum BackportVisibility {