Skip to content

Conversation

@jacob314
Copy link
Contributor

@jacob314 jacob314 commented Jan 23, 2026

Summary

Change is smaller than it looks.
Most of the changes are trivial boilerplate returning true for key events that were handled and false for ones that weren't.
This let us simplify the way we handle when multiple components handle the same events.

Details

Summary of Changes

This PR performs a systemic overhaul of keyboard handling in Gemini CLI, transitioning to a priority-based bubbling system. It also refactors AskUserDialog for better consistency and maintainability.

Intent and PR Hygiene

  • PR Title: Currently "Code review cleanup". Please update to follow Conventional Commits (e.g., refactor(cli): overhaul keyboard handling and AskUserDialog).
  • Description: The PR description is empty. Please provide a brief summary of the changes and the motivation behind the priority-based keypress system.

Architecture and Keyboard Handling

  • Boolean Returns: The shift to boolean | void for KeypressHandler is an excellent architectural improvement. It allows components to explicitly signal whether they've handled an event, enabling clean bubbling.
  • Priority Stack: The implementation of prioritySubscribers and normalSubscribers in KeypressContext correctly uses a stack-like behavior (reverse iteration), ensuring that the most recently mounted components (like dialogs or overlays) get first priority.
  • Verification: Verified that AppContainer (persistent root) registers first and thus runs last in the normal priority queue, allowing dynamic overlays to correctly intercept global shortcuts.

Refactoring and UI/UX

  • AskUserDialog: The refactor to use useTabbedNavigation and shared components is a great reduction in complexity.
  • DialogFooter: This is a solid addition for maintaining visual consistency across dialogs.
  • Accessibility: Good use of aria-role="tablist" and aria-label in the new AskUserDialog structure.

Technical Issues and Suggestions

  • Type Bug in TextBuffer: In packages/cli/src/ui/components/shared/text-buffer.ts, the TextBuffer interface still defines handleInput: (key: Key) => void;. This should be updated to boolean to match the implementation.
  • AskUserDialog Layout Regression: Snapshot changes indicate that ChoiceQuestionView, TextQuestionView, and ReviewView are now shrinking to fit their content width instead of taking the full available width.
    • Recommendation: Add width="100%" to the outer Box of these components to ensure they occupy the availableWidth provided by AskUserDialog and maintain visual stability.
  • Unicode Literals: Using literal characters like and in TabHeader.tsx is fine for this codebase, but ensure your editor is configured for UTF-8 to avoid accidental corruption.

Tests Audit

  • waitFor: Correct use of the custom waitFor from test-utils/async.js instead of vi.waitFor.
  • Regression Test: The new BubblingRegression.test.tsx is a high-value addition that prevents future regressions in the new bubbling logic.
  • Snapshots: Snapshot changes in SettingsDialog were verified as consequences of the shared component updates.

The aria tweaks aren't really needed but are harmless and could help in the future.

@jacob314 jacob314 requested a review from a team as a code owner January 23, 2026 22:42
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @jacob314, 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 refactors and enhances the user experience for CLI dialogs, particularly focusing on keyboard navigation and input handling. By introducing new dialog navigation commands, centralizing tab-based navigation with a dedicated hook, and implementing a priority system for keypress events, it addresses issues related to event bubbling and ensures a more intuitive and consistent interaction model. The changes also include UI improvements for keyboard hints and accessibility.

Highlights

  • Enhanced Dialog Navigation: Introduced new DIALOG_NEXT and DIALOG_PREV commands, mapping them to Tab and Shift+Tab respectively, to improve navigation within dialogs.
  • Refactored AskUserDialog: The AskUserDialog component was significantly refactored to remove internal state for question indexing and cursor edge tracking. It now leverages a new useTabbedNavigation hook for managing question flow and navigation, simplifying its logic.
  • Priority Keypress Handling: The KeypressContext and useKeypress hook were updated to support priority subscribers. This allows certain components, like text inputs, to consume keypress events before other, lower-priority subscribers, preventing unintended event bubbling (e.g., typing 'j' in a text input no longer triggers list navigation).
  • New DialogFooter Component: A reusable DialogFooter component was added to standardize the display of keyboard hints and shortcuts across various dialogs, ensuring consistent UI and user experience.
  • Improved Text Input Behavior: The useTextBuffer hook now explicitly indicates when a keypress is handled and prevents arrow key navigation from bubbling up if the cursor is not at the edge of the input field. This fixes a regression where typing in a custom option field could inadvertently trigger navigation.
  • Accessibility Enhancements: Added aria-role="tablist" and aria-current="step" attributes to TabHeader for improved accessibility.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions
Copy link

github-actions bot commented Jan 23, 2026

Size Change: +8.92 kB (+0.04%)

Total Size: 23.5 MB

Filename Size Change
./bundle/gemini.js 23.5 MB +8.92 kB (+0.04%)
ℹ️ View Unchanged
Filename Size
./bundle/sandbox-macos-permissive-closed.sb 1.03 kB
./bundle/sandbox-macos-permissive-open.sb 890 B
./bundle/sandbox-macos-permissive-proxied.sb 1.31 kB
./bundle/sandbox-macos-restrictive-closed.sb 3.29 kB
./bundle/sandbox-macos-restrictive-open.sb 3.36 kB
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB

compressed-size-action

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request is a significant and well-executed refactoring of the keypress handling system within the CLI UI. It introduces a priority-based subscription model that allows keypress handlers to consume events, preventing them from bubbling up. This effectively resolves issues where global navigation shortcuts could be unintentionally triggered from within text input fields. The changes are extensive, touching numerous components and hooks, but are implemented consistently. The addition of a new regression test to verify the fix is a great touch. I've identified one high-severity issue where a component prop was being ignored, which could lead to UI layout inconsistencies.

@gemini-cli gemini-cli bot added the priority/p1 Important and should be addressed in the near term. label Jan 23, 2026
@jacob314 jacob314 force-pushed the ask_question_cleanup branch from 8f93a9c to df37466 Compare January 24, 2026 07:46
@jacob314 jacob314 requested a review from a team as a code owner January 24, 2026 07:46
@jacob314
Copy link
Contributor Author

jacob314 commented Jan 24, 2026

Detailed Code Review for PR 17414

Overall, this is a high-quality PR that significantly improves the CLI's internal event plumbing.


const handleInput = useCallback(
(key: Key): void => {
(key: Key): boolean => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these changes are all trivial. We return true after each key we handled and false for ones where the key didn't cause an action.

});

writeKey(stdin, '\x1b[D'); // Left arrow should work when NOT focusing a text input
// Wait, Async question is a CHOICE question, so Left arrow SHOULD work.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cleanup of no-op comment

@gemini-cli gemini-cli bot added the status/need-issue Pull requests that need to have an associated issue. label Jan 24, 2026
@jackwotherspoon jackwotherspoon changed the title Code review cleanup refactor(cli): keyboard handling and AskUserDialog Jan 24, 2026
Copy link
Contributor

@jackwotherspoon jackwotherspoon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM ✅

@jacob314 jacob314 enabled auto-merge January 26, 2026 17:42
@gemini-cli
Copy link
Contributor

gemini-cli bot commented Jan 27, 2026

Hi there! Thank you for your contribution to Gemini CLI.

To improve our contribution process and better track changes, we now require all pull requests to be associated with an existing issue, as announced in our recent discussion and as detailed in our CONTRIBUTING.md.

This pull request is being closed because it is not currently linked to an issue. Once you have updated the description of this PR to link an issue (e.g., by adding Fixes #123 or Related to #123), it will be automatically reopened.

How to link an issue:
Add a keyword followed by the issue number (e.g., Fixes #123) in the description of your pull request. For more details on supported keywords and how linking works, please refer to the GitHub Documentation on linking pull requests to issues.

Thank you for your understanding and for being a part of our community!

@gemini-cli gemini-cli bot closed this Jan 27, 2026
auto-merge was automatically disabled January 27, 2026 02:45

Pull request was closed

@jacob314 jacob314 enabled auto-merge January 27, 2026 06:48
@jacob314 jacob314 disabled auto-merge January 27, 2026 21:34
@jacob314 jacob314 enabled auto-merge January 27, 2026 21:34
@jacob314 jacob314 added this pull request to the merge queue Jan 27, 2026
Merged via the queue into main with commit b51323b Jan 27, 2026
25 checks passed
@jacob314 jacob314 deleted the ask_question_cleanup branch January 27, 2026 22:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority/p1 Important and should be addressed in the near term. status/need-issue Pull requests that need to have an associated issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants