feat(ui): dynamically generate all keybinding hints#21346
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the user experience by introducing context-aware keybinding hints across the CLI's user interface. Instead of static, potentially incorrect key labels, the system now dynamically displays the appropriate key combinations for the user's operating system. This change centralizes keybinding formatting logic, improves consistency between the UI and documentation, and strengthens testing robustness for platform-dependent features. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request effectively refactors the keybinding UI hints to be context-aware, centralizing the logic in keybindingUtils.ts and updating various components to use it. This is a great improvement for cross-platform consistency. My review identified a couple of issues: an incorrect test snapshot for the ShortcutsHelp component on macOS, and the removal of a test for ToolConfirmationQueue which appears to hide an unaddressed hardcoded keybinding. Addressing these will ensure the feature is completely and correctly implemented.
I am having trouble creating individual review comments. Click here to see my feedback.
packages/cli/src/ui/components/snapshots/ShortcutsHelp.test.tsx.snap (29)
The snapshot for the narrow mode on macOS incorrectly shows Alt+M for the 'raw markdown mode' shortcut. On macOS, this should be Option+M, as correctly reflected in the wide mode snapshot. This suggests a potential issue in the test setup, possibly related to state leakage between parameterized tests, causing an incorrect platform context to be used. Please investigate and correct the snapshot to ensure the proper keybinding is displayed for macOS users.
packages/cli/src/ui/components/snapshots/ToolConfirmationQueue.test.tsx.snap (93-118)
This snapshot test for ToolConfirmationQueue has been removed. The test, renders a multiline shell command with syntax highlighting and redirection warning (SVG snapshot) 1, was asserting the presence of a hardcoded keybinding hint (Shift+Tab). The removal of this test is concerning because ToolConfirmationQueue.tsx was not updated to use the new dynamic formatCommand utility, and this removal appears to be hiding a regression or an incomplete implementation.
To ensure all user-facing keybinding hints are context-aware as intended by this PR, please reinstate this test and update ToolConfirmationQueue.tsx to use formatCommand for its keybinding hints.
|
Size Change: +1.75 kB (+0.01%) Total Size: 26 MB
ℹ️ View Unchanged
|
fea8602 to
dbc9520
Compare
dbc9520 to
ff0bfd6
Compare
There was a problem hiding this comment.
Code Review
This pull request is a great improvement, centralizing the keybinding logic into a dynamic, platform-aware utility. The changes to the UI components and the documentation generation script create a much more maintainable and consistent system. The enhanced tests also add significant value. I've found one area that appears to have been missed during the refactoring, which I've detailed in a specific comment.
I am having trouble creating individual review comments. Click here to see my feedback.
packages/cli/src/ui/components/snapshots/ToolConfirmationQueue.test.tsx.snap (93-118)
This snapshot, which contains a hardcoded keybinding hint for Shift+Tab, is being deleted. The goal of this PR is to make all keybinding hints dynamic, but it seems the ToolConfirmationQueue component was missed during the audit mentioned in the PR description.
Instead of deleting this test case, please update ToolConfirmationQueue.tsx to use the new formatCommand(Command.CYCLE_APPROVAL_MODE) utility for the hint, and then update the snapshot accordingly. This will ensure all user-facing keybindings are handled dynamically and consistently.
This is a spurious error. The test had been removed in a previous PR but they forgot to remove the snapshot for it. |
ff0bfd6 to
a8ff847
Compare
Shouldn't we just remove the snapshot in this case? |
Resolves #21294 by centralizing keybinding formatting and dynamically resolving labels based on the user's OS and configuration.
a8ff847 to
da2ab83
Compare
Yes. That's what my PR does. Gemini was confused because it saw me removing the snapshot and thought I had removed the test. |
Summary
Dynamically generate all keybinding hints
Details
keybindingUtils.tsto use platform-specific maps. macOS now correctly identifiesOptionandCmd, while Windows and Linux useAlt,Win, andSuper.ShortcutsHelp,Help,ApprovalModeIndicator,RawMarkdownIndicator, andTodoTray) to resolve keybindings dynamically viaformatCommand.generate-keybindings-doc.tsscript to use the same centralized logic, ensuringkeyboard-shortcuts.mdalways reflects the actual CLI behavior accurately.'default'platform fallback whenFORCE_GENERIC_KEYBINDING_HINTSis set in the environment to prevent cross-OS snapshot thrashing.ShortcutsHelp.test.tsxandRawMarkdownIndicator.test.tsxwithbeforeAllhooks to explicitly clear the stub and test platform variations.keybindingUtils.test.tsinto a parameterized suite for robustness.Related Issues
For #21294.
How to Validate
Verify hints show properly.
Pre-Merge Checklist