fix(cli-ui): add modifyOtherKeys fallback for Ctrl+Backspace word delete#25943
fix(cli-ui): add modifyOtherKeys fallback for Ctrl+Backspace word delete#25943TinyblackQvQ wants to merge 2 commits intogoogle-gemini:mainfrom
Conversation
…etion The revert PR google-gemini#25941 removed the Windows heuristic that incorrectly set ctrl=true for \b, which fixed the Backspace/Ctrl+Backspace swap bug. However, Ctrl+Backspace remained non-functional in terminals that use modifyOtherKeys (the fallback path when Kitty protocol is unavailable). This adds code 8 to KITTY_CODE_MAP so that the modifyOtherKeys sequence \x1b[27;5;8~ is properly decoded as Ctrl+Backspace, restoring word deletion in environments like VSCode terminal and xterm.
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 restores the functionality of the Ctrl+Backspace shortcut for word deletion in terminal environments that utilize the modifyOtherKeys protocol. By updating the key mapping and refining the logic for character sequence handling, the changes ensure consistent behavior across different terminal emulators. Highlights
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. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request improves backspace key handling within the KeypressContext. It adds a specific mapping for the backspace key (code 8) to the KITTY_CODE_MAP and refactors the emitKeys function to explicitly differentiate between the \b (often used for ctrl+h or ctrl+backspace on Windows) and \x7f characters. I have no feedback to provide.
|
it doesnt work. npm 11.3.0 |
@dogukanozen Thanks for testing this PR on CMD. You're right. This fix in #25943 doesn't work on Windows Command Prompt (CMD). The reason is that CMD (the legacy console host) does not support either the Kitty protocol or In Windows CMD, there is a distinction: However, the problem is that this mapping is not standardized across all legacy terminals. Different old terminals (or different configurations of the same terminal) may:
If we hardcode an assumption based on CMD's behavior, we risk breaking the distinction on other terminals – exactly the kind of function swap that the original bug exhibited. Since there's no reliable way to detect which mapping a given legacy terminal uses, the only safe choice is to rely on protocols (Kitty / As a workaround, |
|
it doesnt work on ps too @TinyblackQvQ |
Hi @dogukanozen. Thank you for the follow-up, and I apologize for the earlier mistaken conclusion. My original testing was done in PowerShell launched from within VS Code, where After several hours of debugging, log analysis, and data collection, I believe I've identified the root cause. The issue is not related to specific PowerShell or CMD versions — it lies deeper in the Windows input event handling chain, specifically within the terminal emulation layer. Input Event Flow in Windows Standalone Terminals flowchart TB
Keyboard --> |✓ Raw Input Event| Kernel --> |✓ Raw Input Event| WTH[Windows Terminal Host]
subgraph Terminal[Windows Terminal]
WTH --> |✓ VT Sequence| ConPTY
end
subgraph ConPTY[conhost.exe/ConPTY]
VtInputThread --> |✓ VT Sequence| InputStateMachine --> |✓ INPUT_RECORD Sequence| ConsoleBuffer
end
subgraph ReadMode
ConsoleBuffer --> A[Line Mode \n API:ReadConsoleInput]
ConsoleBuffer --> B[Raw Mode \n API:ReadFile]
end
A --> |✓ INPUT_RECORD| App[Application]
B --> |✗ Mapped Byte Stream| App
Executor[PowerShell/CMD] -.->|API Hook by| ConPTY
The critical problem occurs after the Windows Terminal Host transmits a complete CSI sequence to
As a result, the application only receives One could attempt to forcibly map Why This Cannot Be Fixed at the Application Level This issue cannot be resolved within Gemini CLI or any other application, because the necessary distinction is lost before the application ever sees the input. The only reliable fix is to bypass the remapping layer entirely, which requires Windows Terminal version 1.25 or later, where Kitty protocol support is available. The Kitty protocol allows Why VS Code Works Correctly (And Why I Was Mistaken) In VS Code, keyboard events are intercepted at the Conclusion The inability to reliably distinguish |
|
thanks, this makes sense. |
spencer426
left a comment
There was a problem hiding this comment.
Thanks for adding this modifyOtherKeys fallback for Ctrl+Backspace!
Overall the logic looks correct. However, please add test coverage for the new sequences to ensure we don't regress on this behavior in the future.
Could you address the comments below?
| 3: { name: 'delete' }, | ||
| 5: { name: 'pageup' }, | ||
| 6: { name: 'pagedown' }, | ||
| 8: { name: 'backspace' }, |
There was a problem hiding this comment.
Improvement (Minor):
Please add a test case for this new modifyOtherKeys fallback sequence (\x1b[27;5;8~) in packages/cli/src/ui/contexts/KeypressContext.test.tsx. There is an existing block called "Parameterized functional keys" where this would fit perfectly.
| } else if (ch === '\b' || ch === '\x7f') { | ||
| // backspace or ctrl+h | ||
| } else if (ch === '\b') { | ||
| // ctrl+h / ctrl+backspace (windows terminals send \x08 for ctrl+backspace) |
There was a problem hiding this comment.
Improvement (Minor):
Since \b and \x7f have been decoupled here, please make sure there are tests in KeypressContext.test.tsx that explicitly verify that both codes resolve to backspace appropriately (under the "Tab, Backspace, and Space handling" block).
Also, just a small nit: the comment here mentions "windows terminals send \x08 for ctrl+backspace". If Windows sends a bare \x08, it will be resolved as name: 'backspace', ctrl: false since the alt/ctrl flags default to false without a specific sequence modifier. This is different from modifyOtherKeys which sets ctrl: true. Just want to make sure the Windows heuristic works as intended for deleting whole words in text-buffer.ts!
Summary
The revert PR #25941 removed the Windows heuristic that incorrectly set
ctrl=truefor\b, which fixed the Backspace/Ctrl+Backspace swap bug. However, Ctrl+Backspace remained non-functional in terminals that use modifyOtherKeys (the fallback path when Kitty protocol is unavailable).This adds code 8 to
KITTY_CODE_MAPso that the modifyOtherKeys sequence\x1b[27;5;8~is properly decoded as Ctrl+Backspace, restoring word deletion in environments like VSCode terminal and xterm.Also reverted the merge of
\band\x7fback to separate branches for cleaner structure and future maintainability.Related Issues
Pre-Merge Checklist