Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
18 changes: 10 additions & 8 deletions Sources/KeyboardShortcutSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -272,14 +272,16 @@ enum KeyboardShortcutSettings {
return StoredShortcut(key: "u", command: true, shift: true, option: false, control: false)
case .focusRightSidebar:
return StoredShortcut(key: "e", command: true, shift: true, option: false, control: false)
case .switchRightSidebarToFiles,
.switchRightSidebarToFind,
.switchRightSidebarToSessions,
.switchRightSidebarToFeed,
.switchRightSidebarToDock:
// Legacy cmux.json bindings still resolve, but these mode
// switches do not ship as public default shortcuts.
return .unbound
case .switchRightSidebarToFiles:
return StoredShortcut(key: "1", command: false, shift: false, option: false, control: true)
case .switchRightSidebarToFind:
return StoredShortcut(key: "2", command: false, shift: false, option: false, control: true)
case .switchRightSidebarToSessions:
return StoredShortcut(key: "3", command: false, shift: false, option: false, control: true)
case .switchRightSidebarToFeed:
return StoredShortcut(key: "4", command: false, shift: false, option: false, control: true)
case .switchRightSidebarToDock:
return StoredShortcut(key: "5", command: false, shift: false, option: false, control: true)
Comment thread
lawrencecchen marked this conversation as resolved.
Resolved
case .triggerFlash:
return StoredShortcut(key: "h", command: true, shift: true, option: false, control: false)
case .nextSidebarTab:
Expand Down
65 changes: 54 additions & 11 deletions cmuxTests/ShortcutAndCommandPaletteTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1111,21 +1111,26 @@ final class RightSidebarModeShortcutHintTests: XCTestCase {
XCTAssertEqual(RightSidebarMode.dock.shortcutAction, .switchRightSidebarToDock)
}

func testModeShortcutsAreUnboundByDefault() {
XCTAssertNil(
RightSidebarMode.modeShortcut(for: makeKeyDownEvent(key: "1", modifiers: [.control], keyCode: 18))
func testModeShortcutsUsePrivateControlDigitDefaults() {
XCTAssertEqual(
RightSidebarMode.modeShortcut(for: makeKeyDownEvent(key: "1", modifiers: [.control], keyCode: 18)),
.files
)
XCTAssertNil(
RightSidebarMode.modeShortcut(for: makeKeyDownEvent(key: "2", modifiers: [.control], keyCode: 19))
XCTAssertEqual(
RightSidebarMode.modeShortcut(for: makeKeyDownEvent(key: "2", modifiers: [.control], keyCode: 19)),
.find
)
XCTAssertNil(
RightSidebarMode.modeShortcut(for: makeKeyDownEvent(key: "3", modifiers: [.control], keyCode: 20))
XCTAssertEqual(
RightSidebarMode.modeShortcut(for: makeKeyDownEvent(key: "3", modifiers: [.control], keyCode: 20)),
.sessions
)
XCTAssertNil(
RightSidebarMode.modeShortcut(for: makeKeyDownEvent(key: "4", modifiers: [.control], keyCode: 21))
XCTAssertEqual(
RightSidebarMode.modeShortcut(for: makeKeyDownEvent(key: "4", modifiers: [.control], keyCode: 21)),
.feed
)
XCTAssertNil(
RightSidebarMode.modeShortcut(for: makeKeyDownEvent(key: "5", modifiers: [.control], keyCode: 23))
XCTAssertEqual(
RightSidebarMode.modeShortcut(for: makeKeyDownEvent(key: "5", modifiers: [.control], keyCode: 23)),
.dock
)
}

Expand All @@ -1148,6 +1153,44 @@ final class RightSidebarModeShortcutHintTests: XCTestCase {
)
}

func testModeShortcutUsesSettingsFileBindings() throws {
let settingsFileURL = try XCTUnwrap(temporaryDirectoryURL)
.appendingPathComponent("cmux.json", isDirectory: false)
try """
{
"shortcuts": {
"switchRightSidebarToFiles": "ctrl+8"
}
}
""".write(to: settingsFileURL, atomically: true, encoding: .utf8)
KeyboardShortcutSettings.settingsFileStore.reload()
KeyboardShortcutSettings.notifySettingsFileDidChange()

XCTAssertEqual(
RightSidebarMode.modeShortcut(for: makeKeyDownEvent(key: "8", modifiers: [.control], keyCode: 28)),
.files
)
XCTAssertNil(
RightSidebarMode.modeShortcut(for: makeKeyDownEvent(key: "1", modifiers: [.control], keyCode: 18))
)
XCTAssertEqual(
RightSidebarMode.modeShortcut(for: makeKeyDownEvent(key: "2", modifiers: [.control], keyCode: 19)),
.find
)
XCTAssertEqual(
RightSidebarMode.modeShortcut(for: makeKeyDownEvent(key: "3", modifiers: [.control], keyCode: 20)),
.sessions
)
XCTAssertEqual(
RightSidebarMode.modeShortcut(for: makeKeyDownEvent(key: "4", modifiers: [.control], keyCode: 21)),
.feed
)
XCTAssertEqual(
RightSidebarMode.modeShortcut(for: makeKeyDownEvent(key: "5", modifiers: [.control], keyCode: 23)),
.dock
)
}
Comment thread
lawrencecchen marked this conversation as resolved.
Resolved

func testFocusRightSidebarShortcutCanBeOverwrittenForHintRendering() {
let customShortcut = StoredShortcut(
key: "e",
Expand Down
22 changes: 13 additions & 9 deletions cmuxTests/WorkspaceUnitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -356,17 +356,21 @@ final class WorkspaceRenameShortcutDefaultsTests: XCTestCase {
XCTAssertFalse(findInDirectory.control)
}

func testRightSidebarModeSwitchesAreNotPublicDefaultShortcuts() {
let modeSwitchActions: [KeyboardShortcutSettings.Action] = [
.switchRightSidebarToFiles,
.switchRightSidebarToFind,
.switchRightSidebarToSessions,
.switchRightSidebarToFeed,
.switchRightSidebarToDock,
func testRightSidebarModeSwitchesHavePrivateControlDigitDefaults() {
let modeSwitchActions: [(KeyboardShortcutSettings.Action, String)] = [
(.switchRightSidebarToFiles, "1"),
(.switchRightSidebarToFind, "2"),
(.switchRightSidebarToSessions, "3"),
(.switchRightSidebarToFeed, "4"),
(.switchRightSidebarToDock, "5"),
]

for action in modeSwitchActions {
XCTAssertTrue(action.defaultShortcut.isUnbound)
for (action, key) in modeSwitchActions {
XCTAssertEqual(action.defaultShortcut.key, key)
XCTAssertFalse(action.defaultShortcut.command)
XCTAssertFalse(action.defaultShortcut.shift)
XCTAssertFalse(action.defaultShortcut.option)
XCTAssertTrue(action.defaultShortcut.control)
XCTAssertFalse(action.isPublicShortcutAction)
XCTAssertFalse(KeyboardShortcutSettings.publicShortcutActions.contains(action))
XCTAssertFalse(KeyboardShortcutSettings.settingsVisibleActions.contains(action))
Expand Down
Loading