Add ctrl-k command palette regression tests

This commit is contained in:
Lawrence Chen 2026-03-30 18:38:39 -07:00
parent 2d2d8da1c7
commit 1dab226bcc
No known key found for this signature in database
3 changed files with 82 additions and 17 deletions

View file

@ -2445,6 +2445,72 @@ final class AppDelegateShortcutRoutingTests: XCTestCase {
XCTAssertEqual(observedDelta, 1) XCTAssertEqual(observedDelta, 1)
} }
func testControlKDoesNotRoutePaletteMoveSelectionWhenSearchFieldIsFocused() {
guard let appDelegate = AppDelegate.shared else {
XCTFail("Expected AppDelegate.shared")
return
}
let windowId = appDelegate.createMainWindow()
defer {
closeWindow(withId: windowId)
}
guard let window = window(withId: windowId),
let contentView = window.contentView else {
XCTFail("Expected test window")
return
}
let overlayContainer = NSView(frame: contentView.bounds)
overlayContainer.identifier = commandPaletteOverlayContainerIdentifier
overlayContainer.alphaValue = 1
overlayContainer.isHidden = false
contentView.addSubview(overlayContainer)
let fieldEditor = CommandPaletteMarkedTextFieldEditor(frame: NSRect(x: 0, y: 0, width: 200, height: 24))
fieldEditor.isFieldEditor = true
overlayContainer.addSubview(fieldEditor)
XCTAssertTrue(window.makeFirstResponder(fieldEditor))
appDelegate.setCommandPaletteVisible(false, for: window)
defer {
overlayContainer.removeFromSuperview()
fieldEditor.removeFromSuperview()
}
let moveExpectation = expectation(
description: "Ctrl+K should not be rerouted as command palette move-selection"
)
moveExpectation.isInverted = true
let moveToken = NotificationCenter.default.addObserver(
forName: .commandPaletteMoveSelection,
object: nil,
queue: nil
) { _ in
moveExpectation.fulfill()
}
defer { NotificationCenter.default.removeObserver(moveToken) }
guard let controlKEvent = makeKeyDownEvent(
key: "\u{0b}",
modifiers: [.control],
keyCode: 40,
windowNumber: window.windowNumber
) else {
XCTFail("Failed to construct Ctrl+K event")
return
}
#if DEBUG
XCTAssertFalse(appDelegate.debugHandleCustomShortcut(event: controlKEvent))
#else
XCTFail("debugHandleCustomShortcut is only available in DEBUG")
#endif
wait(for: [moveExpectation], timeout: 0.2)
}
func testEscapeDismissesCommandPaletteWhenVisibilityStateStaysStalePastInitialPendingWindow() { func testEscapeDismissesCommandPaletteWhenVisibilityStateStaysStalePastInitialPendingWindow() {
guard let appDelegate = AppDelegate.shared else { guard let appDelegate = AppDelegate.shared else {
XCTFail("Expected AppDelegate.shared") XCTFail("Expected AppDelegate.shared")

View file

@ -213,7 +213,7 @@ final class CommandPaletteKeyboardNavigationTests: XCTestCase {
) )
} }
func testControlLetterNavigationSupportsPrintableAndControlChars() { func testControlLetterNavigationSupportsPrintableAndControlCharsForNPOnly() {
XCTAssertEqual( XCTAssertEqual(
commandPaletteSelectionDeltaForKeyboardNavigation( commandPaletteSelectionDeltaForKeyboardNavigation(
flags: [.control], flags: [.control],
@ -246,37 +246,36 @@ final class CommandPaletteKeyboardNavigationTests: XCTestCase {
), ),
-1 -1
) )
XCTAssertEqual( }
func testDoesNotTreatControlJKAsPaletteNavigation() {
XCTAssertNil(
commandPaletteSelectionDeltaForKeyboardNavigation( commandPaletteSelectionDeltaForKeyboardNavigation(
flags: [.control], flags: [.control],
chars: "j", chars: "j",
keyCode: 38 keyCode: 38
),
1
) )
XCTAssertEqual( )
XCTAssertNil(
commandPaletteSelectionDeltaForKeyboardNavigation( commandPaletteSelectionDeltaForKeyboardNavigation(
flags: [.control], flags: [.control],
chars: "\u{0a}", chars: "\u{0a}",
keyCode: 38 keyCode: 38
),
1
) )
XCTAssertEqual( )
XCTAssertNil(
commandPaletteSelectionDeltaForKeyboardNavigation( commandPaletteSelectionDeltaForKeyboardNavigation(
flags: [.control], flags: [.control],
chars: "k", chars: "k",
keyCode: 40 keyCode: 40
),
-1
) )
XCTAssertEqual( )
XCTAssertNil(
commandPaletteSelectionDeltaForKeyboardNavigation( commandPaletteSelectionDeltaForKeyboardNavigation(
flags: [.control], flags: [.control],
chars: "\u{0b}", chars: "\u{0b}",
keyCode: 40 keyCode: 40
), )
-1
) )
} }

View file

@ -3,8 +3,8 @@
Regression test: command palette list navigation keys. Regression test: command palette list navigation keys.
Validates: Validates:
- Down: ArrowDown, Ctrl+N, Ctrl+J - Down: ArrowDown, Ctrl+N
- Up: ArrowUp, Ctrl+P, Ctrl+K - Up: ArrowUp, Ctrl+P
""" """
import os import os
@ -125,10 +125,10 @@ def main() -> int:
message="no focused surface available for command palette context", message="no focused surface available for command palette context",
) )
for combo in ("down", "ctrl+n", "ctrl+j"): for combo in ("down", "ctrl+n"):
_assert_move(client, window_id, combo, start_index=0, expected_index=1) _assert_move(client, window_id, combo, start_index=0, expected_index=1)
for combo in ("up", "ctrl+p", "ctrl+k"): for combo in ("up", "ctrl+p"):
_assert_move(client, window_id, combo, start_index=1, expected_index=0) _assert_move(client, window_id, combo, start_index=1, expected_index=0)
_assert_can_navigate_past_ten_results(client, window_id) _assert_can_navigate_past_ten_results(client, window_id)