Skip to content

fix(cli-ui): add modifyOtherKeys fallback for Ctrl+Backspace word delete#25943

Open
TinyblackQvQ wants to merge 2 commits intogoogle-gemini:mainfrom
TinyblackQvQ:fix/ctrl-backspace-modifyotherkeys-fallback
Open

fix(cli-ui): add modifyOtherKeys fallback for Ctrl+Backspace word delete#25943
TinyblackQvQ wants to merge 2 commits intogoogle-gemini:mainfrom
TinyblackQvQ:fix/ctrl-backspace-modifyotherkeys-fallback

Conversation

@TinyblackQvQ
Copy link
Copy Markdown

Summary

The revert PR #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.

Also reverted the merge of \b and \x7f back to separate branches for cleaner structure and future maintainability.

Related Issues

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

…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.
@TinyblackQvQ TinyblackQvQ requested a review from a team as a code owner April 24, 2026 21:12
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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

  • Ctrl+Backspace Support: Added code 8 to KITTY_CODE_MAP to correctly decode modifyOtherKeys sequences for Ctrl+Backspace.
  • Code Refactoring: Separated the handling of '\b' and '\x7f' characters to improve maintainability and clarity in key event processing.
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.

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.

Copy link
Copy Markdown
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 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.

@gemini-cli gemini-cli Bot added area/core Issues related to User Interface, OS Support, Core Functionality help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! labels Apr 24, 2026
@dogukanozen
Copy link
Copy Markdown
Contributor

it doesnt work.

npm 11.3.0
node 24.14.0
terminal cmd Version 10.0.26200.8246
Win 11
Gemini CLI v0.41.0-nightly.20260423.gaa05b4583
branch pr-25943

@TinyblackQvQ
Copy link
Copy Markdown
Author

TinyblackQvQ commented Apr 25, 2026

it doesnt work.

npm 11.3.0 node 24.14.0 terminal cmd Version 10.0.26200.8246 Win 11 Gemini CLI v0.41.0-nightly.20260423.gaa05b4583 branch pr-25943

@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 modifyOtherKeys. So when you inputs '\x7f' and '\b', it will be same treated as a plain '\b'.

In Windows CMD, there is a distinction: Ctrl+Backspace sends \x7f, while plain Backspace sends \b. That's why a naive fix like setting ctrl = true on branch checking for ch == '\x7f' would appear to work in CMD. And it does work on my device and environment.

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:

  • Send \b for Ctrl+Backspace and \x7f for plain Backspace

  • Send the same code (e.g., both \x7f) for both keys

  • Send something else entirely

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 / modifyOtherKeys) that provide unambiguous encoded sequences. For terminals that lack those protocols, the correct behavior is to treat both \b and \x7f as a plain Backspace (deleting one character) and not attempt to unconditionally support Ctrl+Backspace across all terminal environments.

As a workaround, Ctrl+W works universally across all terminals (it sends \x17) and triggers word deletion reliably (on else if (!escaped && ch <= '\x1a') branch, KeypressContext.tsx#671). That's the recommended way to delete a word in environments where Ctrl+Backspace cannot be distinguished safely.

@dogukanozen
Copy link
Copy Markdown
Contributor

it doesnt work on ps too @TinyblackQvQ
PSVersion 5.1.26100.8115
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.26100.8115
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

@TinyblackQvQ
Copy link
Copy Markdown
Author

it doesnt work on ps too @TinyblackQvQ PSVersion 5.1.26100.8115 PSEdition Desktop PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...} BuildVersion 10.0.26100.8115 CLRVersion 4.0.30319.42000 WSManStackVersion 3.0 PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1

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 Ctrl+Backspace worked correctly. That led me to believe the issue was fully resolved. However, when testing in a standalone PowerShell window (outside VS Code), Ctrl+Backspace does not work as expected.

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
Loading

The critical problem occurs after the Windows Terminal Host transmits a complete CSI sequence to ConPTY. Because the application (PowerShell) uses Raw Mode instead of Line Mode for input, ConPTY is forced to remap raw input into a byte stream. During this remapping, Windows (for compatibility reasons) translates:

  • Ctrl+Backspace\x7f (DEL)
  • Backspace\b (BS)

As a result, the application only receives \x7f and \b. The system internally knows the difference — but that information is lost in the byte stream delivered to the application.

One could attempt to forcibly map \x7f to Ctrl+Backspace and \b to plain Backspace, but this would break on other platforms (Linux, macOS) where the mapping is typically reversed or different. (See Wikipedia: Delete Character for background.)

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 ConPTY to preserve the full keyboard event information, avoiding the lossy ASCII remapping

Why VS Code Works Correctly (And Why I Was Mistaken)

In VS Code, keyboard events are intercepted at the Chromium DOM keydown event level. VS Code then uses the sendSequence API to inject a properly processed byte stream directly into ConPTY. This bypasses the problematic raw-mode remapping, which is why Ctrl+Backspace works in VS Code's integrated terminal but fails in a standalone Windows terminal.

Conclusion

The inability to reliably distinguish Ctrl+Backspace from plain Backspace in standalone Windows terminals (CMD, PowerShell) is a fundamental limitation of the current Windows terminal infrastructure when operating in Raw Mode. The only robust solution is to rely on modern protocols like Kitty (available in Windows Terminal 1.25+) that preserve the full key context. For terminals lacking such protocols, Ctrl+Backspace cannot be safely supported, you could use Ctrl+W as a universal, reliable alternative for word deletion.

@dogukanozen
Copy link
Copy Markdown
Contributor

thanks, this makes sense.
but i think there may still be something at node/input level. in our case node is also between terminal and app.
also in vscode, input seems to be handled earlier line 671 (around } else if (!escaped && ch <= '\x1a') {), so the behavior is different there.
and claude cli had a similar ctrl+backspace issue but fixed it recently. not sure how, but it might be worth checking.
so maybe the root cause is windows terminal, but i’m not sure it’s completely impossible to handle at app level

Copy link
Copy Markdown
Contributor

@spencer426 spencer426 left a comment

Choose a reason for hiding this comment

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

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' },
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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!

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 help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix cli ui: ctrl+backspace does not delete word in windows terminals

3 participants