* Fix terminal keys (arrows, Ctrl+N/P) swallowed after opening browser After a browser panel is shown, SwiftUI's internal focus system activates and its _NSHostingView starts consuming arrow keys and other non-Command key events via performKeyEquivalent, preventing them from reaching the terminal's keyDown handler. Fix: In the NSWindow performKeyEquivalent swizzle, when GhosttyNSView is the first responder and the event has no Command modifier, route directly to the terminal's performKeyEquivalent — bypassing SwiftUI's view hierarchy walk entirely. Also clear stale browserAddressBarFocusedPanelId when a terminal surface has focus, preventing Cmd+N from being eaten by omnibar selection logic after focus transitions away from a browser. Adds DEBUG-only keyboard event ring buffer (KeyDebugLog) that dumps to /tmp/cmux-key-debug.log for diagnosing future key routing issues. * Fix split focus and Cmd+Shift+N swallowed after opening browser Split focus: capture the source terminal's hostedView before bonsplit mutates focusedPaneId, so focusPanel moves focus FROM the old pane instead of from the new pane to itself. Also retry ensureFocus when the new terminal's view has no window yet (matching the existing retry pattern for isVisibleInUI). Cmd+Shift+N: after WKWebView has been in the responder chain, SwiftUI's internal focus system can intercept Command-key events in the content view hierarchy (returning true) without firing the CommandGroup action closure. Fix by dispatching Command-key events directly to NSApp.mainMenu when the terminal is first responder, bypassing the broken SwiftUI path. Also add Cmd+Shift+N to handleCustomShortcut so it's customizable and doesn't depend on SwiftUI menu dispatch at all. * Unified debug event log: merge key/mouse/focus into /tmp/cmux-debug.log - Delete KeyDebugLog, MouseDebugLog, klog(), mlog() from AppDelegate - Replace all klog/mlog calls with dlog() (provided by bonsplit) - Remove debugLogCallback wiring from Workspace - Add focus change logging: focus.panel, focus.firstResponder, split.created, focus.moveFocus - Add import Bonsplit where needed for dlog access - Fix stale drag state on cancelled tab drags (bonsplit submodule) * Fix split focus stolen by re-entrant becomeFirstResponder during reparenting During programmatic splits (Cmd+D / Cmd+Shift+D), SwiftUI reparents the old terminal view, which fires becomeFirstResponder → onFocus → focusPanel for the OLD panel, stealing focus from the newly created pane. Add programmaticFocusTargetPanelId guard to suppress re-entrant focusPanel calls for non-target panels during split creation. Also document the unified debug event log in CLAUDE.md. * Clear stale title/favicon when browser navigation fails When a page fails to load (e.g. connection refused), the tab was still showing the previous page's title and favicon. Now didFailProvisionalNavigation resets pageTitle to the failed URL and clears faviconPNGData. * Fix Cmd+N swallowed by browser omnibar and improve split focus suppression - Only Ctrl+N/P trigger omnibar navigation, not Cmd+N/P (Cmd+N should always create new workspace regardless of address bar focus) - Move split focus suppression from workspace-level guard to source: suppress becomeFirstResponder side-effects (onFocus + ghostty_surface_set_focus) directly on the old GhosttyNSView during reparenting, preventing both model-level and libghostty-level focus divergence - Remove programmaticFocusTargetPanelId from Workspace.focusPanel * Fix omnibar hang, WebView white flash, drag-over-browser, and idle CPU spin - Omnibar: first click selects all without entering NSTextView tracking loop; subsequent clicks have 3s synthetic mouseUp safety net to prevent hang - WebView: set underPageBackgroundColor to match window so new browsers don't flash white before content loads - Drag/drop: register custom UTType (com.splittabbar.tabtransfer) in Info.plist so WKWebView doesn't intercept tab drags; override registerForDraggedTypes on CmuxWebView as belt-and-suspenders - CPU: fix infinite makeFirstResponder loop in controlTextDidEndEditing by checking both the text field and its field editor (the actual first responder)
211 lines
7.8 KiB
Swift
211 lines
7.8 KiB
Swift
import Bonsplit
|
|
import SwiftUI
|
|
|
|
struct SurfaceSearchOverlay: View {
|
|
let surface: TerminalSurface
|
|
@ObservedObject var searchState: TerminalSurface.SearchState
|
|
let onClose: () -> Void
|
|
@State private var corner: Corner = .topRight
|
|
@State private var dragOffset: CGSize = .zero
|
|
@State private var barSize: CGSize = .zero
|
|
@FocusState private var isSearchFieldFocused: Bool
|
|
|
|
private let padding: CGFloat = 8
|
|
|
|
var body: some View {
|
|
GeometryReader { geo in
|
|
HStack(spacing: 4) {
|
|
TextField("Search", text: $searchState.needle)
|
|
.textFieldStyle(.plain)
|
|
.frame(width: 180)
|
|
.padding(.leading, 8)
|
|
.padding(.trailing, 50)
|
|
.padding(.vertical, 6)
|
|
.background(Color.primary.opacity(0.1))
|
|
.cornerRadius(6)
|
|
.focused($isSearchFieldFocused)
|
|
.overlay(alignment: .trailing) {
|
|
if let selected = searchState.selected {
|
|
let totalText = searchState.total.map { String($0) } ?? "?"
|
|
Text("\(selected + 1)/\(totalText)")
|
|
.font(.caption)
|
|
.foregroundColor(.secondary)
|
|
.monospacedDigit()
|
|
.padding(.trailing, 8)
|
|
} else if let total = searchState.total {
|
|
Text("-/\(total)")
|
|
.font(.caption)
|
|
.foregroundColor(.secondary)
|
|
.monospacedDigit()
|
|
.padding(.trailing, 8)
|
|
}
|
|
}
|
|
.onExitCommand {
|
|
if searchState.needle.isEmpty {
|
|
onClose()
|
|
} else {
|
|
surface.hostedView.moveFocus()
|
|
}
|
|
}
|
|
.backport.onKeyPress(.return) { modifiers in
|
|
let action = modifiers.contains(.shift)
|
|
? "navigate_search:previous"
|
|
: "navigate_search:next"
|
|
_ = surface.performBindingAction(action)
|
|
return .handled
|
|
}
|
|
|
|
Button(action: {
|
|
#if DEBUG
|
|
dlog("findbar.next surface=\(surface.id.uuidString.prefix(5))")
|
|
#endif
|
|
_ = surface.performBindingAction("navigate_search:next")
|
|
}) {
|
|
Image(systemName: "chevron.up")
|
|
}
|
|
.buttonStyle(SearchButtonStyle())
|
|
.help("Next match (Return)")
|
|
|
|
Button(action: {
|
|
#if DEBUG
|
|
dlog("findbar.prev surface=\(surface.id.uuidString.prefix(5))")
|
|
#endif
|
|
_ = surface.performBindingAction("navigate_search:previous")
|
|
}) {
|
|
Image(systemName: "chevron.down")
|
|
}
|
|
.buttonStyle(SearchButtonStyle())
|
|
.help("Previous match (Shift+Return)")
|
|
|
|
Button(action: {
|
|
#if DEBUG
|
|
dlog("findbar.close surface=\(surface.id.uuidString.prefix(5))")
|
|
#endif
|
|
onClose()
|
|
}) {
|
|
Image(systemName: "xmark")
|
|
}
|
|
.buttonStyle(SearchButtonStyle())
|
|
.help("Close (Esc)")
|
|
}
|
|
.padding(8)
|
|
.background(.background)
|
|
.clipShape(clipShape)
|
|
.shadow(radius: 4)
|
|
.onAppear {
|
|
NSLog("Find: overlay appear tab=%@ surface=%@", surface.tabId.uuidString, surface.id.uuidString)
|
|
isSearchFieldFocused = true
|
|
}
|
|
.onReceive(NotificationCenter.default.publisher(for: .ghosttySearchFocus)) { notification in
|
|
guard notification.object as? TerminalSurface === surface else { return }
|
|
NSLog("Find: overlay focus tab=%@ surface=%@", surface.tabId.uuidString, surface.id.uuidString)
|
|
DispatchQueue.main.async {
|
|
isSearchFieldFocused = true
|
|
}
|
|
}
|
|
.background(
|
|
GeometryReader { barGeo in
|
|
Color.clear.onAppear {
|
|
barSize = barGeo.size
|
|
}
|
|
}
|
|
)
|
|
.padding(padding)
|
|
.offset(dragOffset)
|
|
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: corner.alignment)
|
|
.gesture(
|
|
DragGesture()
|
|
.onChanged { value in
|
|
dragOffset = value.translation
|
|
}
|
|
.onEnded { value in
|
|
let centerPos = centerPosition(for: corner, in: geo.size, barSize: barSize)
|
|
let newCenter = CGPoint(
|
|
x: centerPos.x + value.translation.width,
|
|
y: centerPos.y + value.translation.height
|
|
)
|
|
let newCorner = closestCorner(to: newCenter, in: geo.size)
|
|
withAnimation(.easeOut(duration: 0.2)) {
|
|
corner = newCorner
|
|
dragOffset = .zero
|
|
}
|
|
}
|
|
)
|
|
}
|
|
}
|
|
|
|
private var clipShape: some Shape {
|
|
RoundedRectangle(cornerRadius: 8)
|
|
}
|
|
|
|
enum Corner {
|
|
case topLeft
|
|
case topRight
|
|
case bottomLeft
|
|
case bottomRight
|
|
|
|
var alignment: Alignment {
|
|
switch self {
|
|
case .topLeft: return .topLeading
|
|
case .topRight: return .topTrailing
|
|
case .bottomLeft: return .bottomLeading
|
|
case .bottomRight: return .bottomTrailing
|
|
}
|
|
}
|
|
}
|
|
|
|
private func centerPosition(for corner: Corner, in containerSize: CGSize, barSize: CGSize) -> CGPoint {
|
|
let halfWidth = barSize.width / 2 + padding
|
|
let halfHeight = barSize.height / 2 + padding
|
|
|
|
switch corner {
|
|
case .topLeft:
|
|
return CGPoint(x: halfWidth, y: halfHeight)
|
|
case .topRight:
|
|
return CGPoint(x: containerSize.width - halfWidth, y: halfHeight)
|
|
case .bottomLeft:
|
|
return CGPoint(x: halfWidth, y: containerSize.height - halfHeight)
|
|
case .bottomRight:
|
|
return CGPoint(x: containerSize.width - halfWidth, y: containerSize.height - halfHeight)
|
|
}
|
|
}
|
|
|
|
private func closestCorner(to point: CGPoint, in containerSize: CGSize) -> Corner {
|
|
let midX = containerSize.width / 2
|
|
let midY = containerSize.height / 2
|
|
|
|
if point.x < midX {
|
|
return point.y < midY ? .topLeft : .bottomLeft
|
|
}
|
|
return point.y < midY ? .topRight : .bottomRight
|
|
}
|
|
}
|
|
|
|
struct SearchButtonStyle: ButtonStyle {
|
|
@State private var isHovered = false
|
|
|
|
func makeBody(configuration: Configuration) -> some View {
|
|
configuration.label
|
|
.foregroundStyle(isHovered || configuration.isPressed ? .primary : .secondary)
|
|
.padding(.horizontal, 2)
|
|
.frame(height: 26)
|
|
.background(
|
|
RoundedRectangle(cornerRadius: 6)
|
|
.fill(backgroundColor(isPressed: configuration.isPressed))
|
|
)
|
|
.onHover { hovering in
|
|
isHovered = hovering
|
|
}
|
|
.backport.pointerStyle(.link)
|
|
}
|
|
|
|
private func backgroundColor(isPressed: Bool) -> Color {
|
|
if isPressed {
|
|
return Color.primary.opacity(0.2)
|
|
}
|
|
if isHovered {
|
|
return Color.primary.opacity(0.1)
|
|
}
|
|
return Color.clear
|
|
}
|
|
}
|