Skip to content

Fix pressing any key to exit select mode.#18421

Merged
jacob314 merged 2 commits intomainfrom
select_mode
Feb 11, 2026
Merged

Fix pressing any key to exit select mode.#18421
jacob314 merged 2 commits intomainfrom
select_mode

Conversation

@jacob314
Copy link
Contributor

@jacob314 jacob314 commented Feb 6, 2026

Summary

Fix bug where only ctrl-S would exit copy mode

Details

This was broken by adding key press bubbling behavior but that same behavior also enables making this support more robust if used correctly.

  • Refactored Keypress Handling: Implemented a new priority-based system for keypress event dispatch, allowing for more granular control over which handlers respond to input.
  • Introduced KeypressPriority Enum: Defined explicit priority levels (Low, Normal, High, Critical) for keypress handlers, ensuring critical actions like exiting copy mode reliably take precedence.
  • Dedicated Copy Mode Exit Handler: Created a specific useKeypress instance with Critical priority to ensure that any keypress exits copy mode when it is active, fixing a previous bug.
  • Improved Test Reliability: Updated tests to simulate keypresses directly via stdin.write using ANSI escape sequences, providing more accurate and robust validation of the new keypress system.

Related Issues

Fixes #18422

@jacob314 jacob314 requested a review from a team as a code owner February 6, 2026 06:08
@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 the application's keyboard input handling mechanism by introducing a robust priority-based system for dispatching keypress events. The core objective is to ensure that specific, critical actions, such as exiting copy mode, reliably take precedence over other input handlers. This change enhances the predictability and correctness of keyboard interactions within the application, particularly for state-dependent behaviors like copy mode, leading to a more stable and intuitive user experience.

Highlights

  • Refactored Keypress Handling: Implemented a new priority-based system for keypress event dispatch, allowing for more granular control over which handlers respond to input.
  • Introduced KeypressPriority Enum: Defined explicit priority levels (Low, Normal, High, Critical) for keypress handlers, ensuring critical actions like exiting copy mode reliably take precedence.
  • Dedicated Copy Mode Exit Handler: Created a specific useKeypress instance with Critical priority to ensure that any keypress exits copy mode when it is active, fixing a previous bug.
  • Improved Test Reliability: Updated tests to simulate keypresses directly via stdin.write using ANSI escape sequences, providing more accurate and robust validation of the new keypress system.
Changelog
  • packages/cli/src/ui/AppContainer.test.tsx
    • Refactored keypress simulation in tests to use stdin.write for more accurate event triggering.
    • Introduced KeypressProvider wrapper for AppContainer in tests.
    • Added a new test case to verify that the copy mode exit handler correctly overrides other priority listeners.
    • Removed direct mocking of useKeypress callback in tests.
  • packages/cli/src/ui/AppContainer.tsx
    • Moved the logic for exiting copy mode on any keypress into a dedicated useKeypress hook with Critical priority.
    • Removed the copyModeEnabled check from the general handleGlobalKeypress callback.
    • Imported KeypressPriority enum.
  • packages/cli/src/ui/contexts/KeypressContext.tsx
    • Implemented a priority-based keypress dispatch system using MultiMap.
    • Defined KeypressPriority enum (Low, Normal, High, Critical) for granular control over handler precedence.
    • Updated subscribe and unsubscribe methods to manage handlers based on their priority.
    • Optimized keypress broadcasting by caching sorted priority levels.
  • packages/cli/src/ui/hooks/useKeypress.ts
    • Updated the useKeypress hook to accept KeypressPriority as an option, allowing developers to specify the priority of their keypress handlers.
    • Maintained backward compatibility for boolean priority values.
Activity
  • The pull request introduces a significant refactoring of the keypress handling system, moving from a simpler, less flexible keypress management to a more robust, priority-based system.
  • This involves architectural changes across multiple files, including the main application container, the keypress context, and the useKeypress hook.
  • Comprehensive updates to the related test file were made to reflect and validate these architectural changes, ensuring the new system behaves as expected.
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 Feb 6, 2026

Size Change: +7.2 kB (+0.03%)

Total Size: 24.3 MB

Filename Size Change
./bundle/gemini.js 24.3 MB +7.2 kB (+0.03%)
ℹ️ 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 introduces a significant and well-executed refactoring of the keypress handling logic. By replacing the previous hook-based approach with a KeypressProvider and a priority-based subscription model, it elegantly solves the issue of keypresses being intercepted before they can exit select/copy mode. The new system, featuring multiple priority levels (Low, Normal, High, Critical), is more robust, maintainable, and extensible. The accompanying test refactoring is also a major improvement, moving from mocking hooks to more realistic integration tests that write directly to stdin. The new test case for handler priority provides strong confidence in the correctness of the fix. Overall, this is an excellent change that improves both functionality and code quality.

@gemini-cli gemini-cli bot added area/core Issues related to User Interface, OS Support, Core Functionality 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item. labels Feb 6, 2026
@jacob314 jacob314 requested a review from sehoon38 February 6, 2026 18:06
@jacob314 jacob314 enabled auto-merge February 6, 2026 18:31
@google-gemini google-gemini deleted a comment from gemini-cli bot Feb 6, 2026
Copy link
Contributor

@sehoon38 sehoon38 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@jacob314 jacob314 added this pull request to the merge queue Feb 6, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 6, 2026
@jacob314 jacob314 added this pull request to the merge queue Feb 6, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 6, 2026
@jacob314 jacob314 added this pull request to the merge queue Feb 6, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 6, 2026
@jacob314 jacob314 added this pull request to the merge queue Feb 7, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 7, 2026
@jacob314 jacob314 added this pull request to the merge queue Feb 10, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 10, 2026
@jacob314 jacob314 added this pull request to the merge queue Feb 11, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 11, 2026
@jacob314 jacob314 added this pull request to the merge queue Feb 11, 2026
Merged via the queue into main with commit eb9223b Feb 11, 2026
27 checks passed
@jacob314 jacob314 deleted the select_mode branch February 11, 2026 17:47
krsjenmt added a commit to krsjenmt/gemini-cli that referenced this pull request Feb 12, 2026
…ini/gemini-cli (#37)

* fix(cli): resolve double rendering in shpool and address vscode lint warnings (google-gemini#18704)

* feat(plan): document and validate Plan Mode policy overrides (google-gemini#18825)

* Fix pressing any key to exit select mode. (google-gemini#18421)

* fix(cli): update F12 behavior to only open drawer if browser fails (google-gemini#18829)

* feat(plan): allow skills to be enabled in plan mode (google-gemini#18817)

Co-authored-by: Jerop Kipruto <jerop@google.com>

* docs(plan): add documentation for plan mode tools (google-gemini#18827)

* Remove experimental note in extension settings docs (google-gemini#18822)

* Update prompt and grep tool definition to limit context size (google-gemini#18780)

* docs(plan): add `ask_user` tool documentation (google-gemini#18830)

* Revert unintended credentials exposure (google-gemini#18840)

* feat(core): update internal utility models to Gemini 3 (google-gemini#18773)

* feat(a2a): add value-resolver for auth credential resolution (google-gemini#18653)

* Removed getPlainTextLength (google-gemini#18848)

* More grep prompt tweaks (google-gemini#18846)

* refactor(cli): Reactive useSettingsStore hook (google-gemini#14915)

* fix(mcp): Ensure that stdio MCP server execution has the `GEMINI_CLI=1` env variable populated. (google-gemini#18832)

* fix(core): improve headless mode detection for flags and query args (google-gemini#18855)

* refactor(cli): simplify UI and remove legacy inline tool confirmation logic (google-gemini#18566)

* feat(cli): deprecate --allowed-tools and excludeTools in favor of policy engine (google-gemini#18508)

* fix(workflows): improve maintainer detection for automated PR actions (google-gemini#18869)

* refactor(cli): consolidate useToolScheduler and delete legacy implementation (google-gemini#18567)

* Update changelog for v0.28.0 and v0.29.0-preview0 (google-gemini#18819)

* fix(core): ensure sub-agents are registered regardless of tools.allowed (google-gemini#18870)

---------

Co-authored-by: Brad Dux <959674+braddux@users.noreply.github.com>
Co-authored-by: Jerop Kipruto <jerop@google.com>
Co-authored-by: Jacob Richman <jacob314@gmail.com>
Co-authored-by: Sandy Tao <sandytao520@icloud.com>
Co-authored-by: Adib234 <30782825+Adib234@users.noreply.github.com>
Co-authored-by: christine betts <chrstn@uw.edu>
Co-authored-by: Christian Gunderman <gundermanc@gmail.com>
Co-authored-by: Adam Weidman <65992621+adamfweidman@users.noreply.github.com>
Co-authored-by: Dev Randalpura <devrandalpura@google.com>
Co-authored-by: Pyush Sinha <pyushsinha20@gmail.com>
Co-authored-by: Richie Foreman <richie.foreman@gmail.com>
Co-authored-by: Gal Zahavi <38544478+galz10@users.noreply.github.com>
Co-authored-by: Abhi <43648792+abhipatel12@users.noreply.github.com>
Co-authored-by: Abhijit Balaji <abhijitbalaji@google.com>
Co-authored-by: Bryan Morgan <bryanmorgan@google.com>
Co-authored-by: g-samroberts <158088236+g-samroberts@users.noreply.github.com>
Co-authored-by: matt korwel <matt.korwel@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Issues related to User Interface, OS Support, Core Functionality 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ctrl-S to select stopped exiting on any key press

2 participants