Repository navigation
Honor Settings rebinding of Global Search (parse package object-form cmux.json bindings) #5143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
austinywang
merged 3 commits into
main
from
issue-5137-global-search-shortcut-configurable
Jun 1, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -94,6 +94,181 @@ final class GlobalSearchShortcutSettingsTests: XCTestCase { | |
| ) | ||
| } | ||
|
|
||
| func testSettingsFileStoreParsesPackageObjectFormGlobalSearchShortcut() throws { | ||
| // Regression for https://github.com/manaflow-ai/cmux/issues/5137. | ||
| // The in-app Settings UI (CmuxSettings package) persists every | ||
| // shortcut rebinding to cmux.json under `shortcuts.bindings.<action>` | ||
| // as a nested StoredShortcut object ({"first": {key, command, ...}}), | ||
| // not the legacy human-editable "cmd+opt+f" string. The file store | ||
| // that feeds KeyboardShortcutSettings — and therefore the system-wide | ||
| // Carbon hotkeys (globalSearch, showHideAllWindows) — must understand | ||
| // that object form. Otherwise SystemWideHotkeyController never sees the | ||
| // rebinding and the default ⌥⌘F keeps opening Global Search. | ||
| let directoryURL = FileManager.default.temporaryDirectory | ||
| .appendingPathComponent("cmux-global-search-object-settings-\(UUID().uuidString)", isDirectory: true) | ||
| try FileManager.default.createDirectory(at: directoryURL, withIntermediateDirectories: true) | ||
| defer { try? FileManager.default.removeItem(at: directoryURL) } | ||
|
|
||
| let settingsFileURL = directoryURL.appendingPathComponent("cmux.json", isDirectory: false) | ||
| try """ | ||
| { | ||
| "shortcuts": { | ||
| "bindings": { | ||
| "globalSearch": { | ||
| "first": { "key": "j", "command": true, "shift": false, "option": false, "control": true } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| """.write(to: settingsFileURL, atomically: true, encoding: .utf8) | ||
|
|
||
| let store = KeyboardShortcutSettingsFileStore( | ||
| primaryPath: settingsFileURL.path, | ||
| fallbackPath: nil, | ||
| startWatching: false | ||
| ) | ||
|
|
||
| XCTAssertEqual( | ||
| store.override(for: .globalSearch), | ||
| StoredShortcut(key: "j", command: true, shift: false, option: false, control: true) | ||
| ) | ||
| } | ||
|
|
||
| func testSettingsFileStoreParsesPackageObjectFormChordShortcut() throws { | ||
| // The package object form also encodes two-stroke chords as | ||
| // {"first": {...}, "second": {...}}. A non-system-wide action exercises | ||
| // the general path so the fix is not narrowed to global search. | ||
| let directoryURL = FileManager.default.temporaryDirectory | ||
| .appendingPathComponent("cmux-chord-object-settings-\(UUID().uuidString)", isDirectory: true) | ||
| try FileManager.default.createDirectory(at: directoryURL, withIntermediateDirectories: true) | ||
| defer { try? FileManager.default.removeItem(at: directoryURL) } | ||
|
|
||
| let settingsFileURL = directoryURL.appendingPathComponent("cmux.json", isDirectory: false) | ||
| try """ | ||
| { | ||
| "shortcuts": { | ||
| "bindings": { | ||
| "newTab": { | ||
| "first": { "key": "b", "command": false, "shift": false, "option": false, "control": true }, | ||
| "second": { "key": "n", "command": false, "shift": false, "option": false, "control": false } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| """.write(to: settingsFileURL, atomically: true, encoding: .utf8) | ||
|
|
||
| let store = KeyboardShortcutSettingsFileStore( | ||
| primaryPath: settingsFileURL.path, | ||
| fallbackPath: nil, | ||
| startWatching: false | ||
| ) | ||
|
|
||
| XCTAssertEqual( | ||
| store.override(for: .newTab), | ||
| StoredShortcut( | ||
| key: "b", | ||
| command: false, | ||
| shift: false, | ||
| option: false, | ||
| control: true, | ||
| chordKey: "n", | ||
| chordCommand: false, | ||
| chordShift: false, | ||
| chordOption: false, | ||
| chordControl: false | ||
| ) | ||
| ) | ||
| } | ||
|
|
||
| func testSettingsFileStoreParsesPackageObjectFormUnboundShortcut() throws { | ||
| // The package marks an explicit "no shortcut" override with an empty | ||
| // primary key ({"first": {"key": ""}}). The legacy reader must treat | ||
| // that as unbound, not as an invalid binding to be dropped. | ||
| let directoryURL = FileManager.default.temporaryDirectory | ||
| .appendingPathComponent("cmux-unbound-object-settings-\(UUID().uuidString)", isDirectory: true) | ||
| try FileManager.default.createDirectory(at: directoryURL, withIntermediateDirectories: true) | ||
| defer { try? FileManager.default.removeItem(at: directoryURL) } | ||
|
|
||
| let settingsFileURL = directoryURL.appendingPathComponent("cmux.json", isDirectory: false) | ||
| try """ | ||
| { | ||
| "shortcuts": { | ||
| "bindings": { | ||
| "globalSearch": { "first": { "key": "", "command": false, "shift": false, "option": false, "control": false } } | ||
| } | ||
| } | ||
| } | ||
| """.write(to: settingsFileURL, atomically: true, encoding: .utf8) | ||
|
|
||
| let store = KeyboardShortcutSettingsFileStore( | ||
| primaryPath: settingsFileURL.path, | ||
| fallbackPath: nil, | ||
| startWatching: false | ||
| ) | ||
|
|
||
| XCTAssertEqual(store.override(for: .globalSearch), .unbound) | ||
| } | ||
|
|
||
| func testSettingsFileStoreRejectsObjectFormChordWithMalformedSecondStroke() throws { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: New tests use XCTest instead of Swift Testing. Project policy requires Swift Testing for new non-CLI unit tests. Prompt for AI agents |
||
| // A present-but-malformed `second` stroke must invalidate the whole | ||
| // binding rather than silently degrading the chord to a single stroke | ||
| // (which could create an unintended single-key shortcut). | ||
| let directoryURL = FileManager.default.temporaryDirectory | ||
| .appendingPathComponent("cmux-bad-chord-object-\(UUID().uuidString)", isDirectory: true) | ||
| try FileManager.default.createDirectory(at: directoryURL, withIntermediateDirectories: true) | ||
| defer { try? FileManager.default.removeItem(at: directoryURL) } | ||
|
|
||
| let settingsFileURL = directoryURL.appendingPathComponent("cmux.json", isDirectory: false) | ||
| try """ | ||
| { | ||
| "shortcuts": { | ||
| "bindings": { | ||
| "newTab": { | ||
| "first": { "key": "b", "command": false, "shift": false, "option": false, "control": true }, | ||
| "second": { "command": false } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| """.write(to: settingsFileURL, atomically: true, encoding: .utf8) | ||
|
|
||
| let store = KeyboardShortcutSettingsFileStore( | ||
| primaryPath: settingsFileURL.path, | ||
| fallbackPath: nil, | ||
| startWatching: false | ||
| ) | ||
|
|
||
| XCTAssertNil(store.override(for: .newTab)) | ||
| } | ||
|
|
||
| func testSettingsFileStoreRejectsObjectFormBareKeyForModifierRequiringAction() throws { | ||
| // Object-form parsing must apply the same bare-first-stroke rule as the | ||
| // string parser: an action that requires a modifier rejects a bare key. | ||
| let directoryURL = FileManager.default.temporaryDirectory | ||
| .appendingPathComponent("cmux-bare-object-\(UUID().uuidString)", isDirectory: true) | ||
| try FileManager.default.createDirectory(at: directoryURL, withIntermediateDirectories: true) | ||
| defer { try? FileManager.default.removeItem(at: directoryURL) } | ||
|
|
||
| let settingsFileURL = directoryURL.appendingPathComponent("cmux.json", isDirectory: false) | ||
| try """ | ||
| { | ||
| "shortcuts": { | ||
| "bindings": { | ||
| "newTab": { "first": { "key": "j", "command": false, "shift": false, "option": false, "control": false } } | ||
| } | ||
| } | ||
| } | ||
| """.write(to: settingsFileURL, atomically: true, encoding: .utf8) | ||
|
|
||
| let store = KeyboardShortcutSettingsFileStore( | ||
| primaryPath: settingsFileURL.path, | ||
| fallbackPath: nil, | ||
| startWatching: false | ||
| ) | ||
|
|
||
| XCTAssertNil(store.override(for: .newTab)) | ||
| } | ||
|
|
||
| func testSettingsFileStoreRejectsGlobalSearchChordBinding() throws { | ||
| let directoryURL = FileManager.default.temporaryDirectory | ||
| .appendingPathComponent("cmux-global-search-invalid-settings-\(UUID().uuidString)", isDirectory: true) | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P3: New unit tests use XCTest. Repo rule says new non-UI tests should use Swift Testing. Migrate these cases to
@Teststyle.Prompt for AI agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Intentional: this extends the existing XCTest suite GlobalSearchShortcutSettingsTests (an XCTestCase). The repo rule migrates files to Swift Testing incrementally when edited and says not to bulk-rewrite untouched tests; mixing @test into an existing XCTestCase isn't possible, so new methods match the file's framework.
— Claude Code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback! I've saved this as a new learning to improve future reviews.