Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Sources/App/ShortcutRoutingSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,28 @@ func shouldDispatchTextBoxInputArrowViaFirstResponderKeyDown(
}
}

/// Ctrl-N / Ctrl-P navigate the mention-completion popover (and emacs-style line
/// movement) inside the terminal textbox. Like plain arrows, the window's
/// `performKeyEquivalent` claims these before they reach the textbox `keyDown`, so
/// they must be routed to the first responder explicitly. Scoped to the textbox so
/// terminal/browser Ctrl-N/Ctrl-P are unaffected.
func shouldDispatchTextBoxInputControlNavViaFirstResponderKeyDown(
keyCode: UInt16,
firstResponderIsTextBoxInput: Bool,
firstResponderHasMarkedText: Bool = false,
flags: NSEvent.ModifierFlags
) -> Bool {
guard firstResponderIsTextBoxInput else { return false }
guard !firstResponderHasMarkedText else { return false }

let normalizedFlags = flags
.intersection(.deviceIndependentFlagsMask)
.subtracting([.numericPad, .function, .capsLock])
guard normalizedFlags == [.control] else { return false }
// kVK_ANSI_N == 45, kVK_ANSI_P == 35
return keyCode == 45 || keyCode == 35
}

func shouldToggleMainWindowFullScreenForCommandControlFShortcut(
flags: NSEvent.ModifierFlags,
chars: String,
Expand Down
16 changes: 16 additions & 0 deletions Sources/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15790,6 +15790,7 @@ private var cmuxBrowserArrowForwardingDepth = 0
private var cmuxBrowserOmnibarMarkedTextForwardingDepth = 0
private var cmuxCommandPaletteArrowForwardingDepth = 0
private var cmuxTextBoxInputArrowForwardingDepth = 0
private var cmuxTextBoxInputControlNavForwardingDepth = 0
private var cmuxWindowFirstResponderBypassDepth = 0
private var cmuxFieldEditorOwningWebViewAssociationKey: UInt8 = 0

Expand Down Expand Up @@ -16614,6 +16615,21 @@ private extension NSWindow {
return true
}

if shouldDispatchTextBoxInputControlNavViaFirstResponderKeyDown(
keyCode: event.keyCode,
firstResponderIsTextBoxInput: firstResponderIsTextBoxInput,
firstResponderHasMarkedText: firstResponderHasMarkedText,
flags: event.modifierFlags
) {
if cmuxTextBoxInputControlNavForwardingDepth > 0 {
return false
}
cmuxTextBoxInputControlNavForwardingDepth += 1
defer { cmuxTextBoxInputControlNavForwardingDepth = max(0, cmuxTextBoxInputControlNavForwardingDepth - 1) }
self.firstResponder?.keyDown(with: event)
return true
}

// Web forms rely on Return/Enter flowing through keyDown. If the original
// NSWindow.performKeyEquivalent consumes Enter first, submission never reaches
// WebKit. Route Return/Enter directly to the current first responder and
Expand Down
Loading
Loading