-
Notifications
You must be signed in to change notification settings - Fork 324
fix(core): recognize Ctrl+Backspace on Windows Terminal and WSL #555
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Windows Terminal and many terminals send \b (ASCII 8) for Ctrl+Backspace, but \x7f (ASCII 127) for regular Backspace. The parser was treating both identically, causing Ctrl+Backspace to not trigger delete-word-backward. Changes: - \x7f now correctly parses as regular backspace (ctrl: false) - \b now correctly parses as Ctrl+Backspace (ctrl: true) - \x1b\x7f parses as Alt+Backspace (meta: true) - \x1b\b parses as Alt+Ctrl+Backspace (meta: true, ctrl: true) Fixes anomalyco/opencode#6991
@opentui/core
@opentui/react
@opentui/solid
@opentui/core-darwin-arm64
@opentui/core-darwin-x64
@opentui/core-linux-arm64
@opentui/core-linux-x64
@opentui/core-win32-arm64
@opentui/core-win32-x64
commit: |
|
I think that could make sense, it does not play well with existing expectations though it seems. |
|
Thanks for the feedback @kommander! You're right - I investigated the CI failures and I see the issue. The change breaks existing expectations around how Current behavior:
My change:
The root cause is terminal semantics divergence:
Options I see:
What approach would you prefer? I'm happy to implement whichever makes most sense for the project. BTW this comment was written by AI |
On Windows, \b (ASCII 8) is Ctrl+Backspace. On Unix/macOS, \b (ASCII 8) is Ctrl+H. This preserves backwards compatibility on macOS/Linux while enabling Ctrl+Backspace word deletion on Windows Terminal/WSL.
|
I've pushed a fix that uses platform detection (Option 1). Changes:
This should:
The tests now use platform detection to validate the expected behavior on each platform. |
WSL reports process.platform as 'linux' but Windows Terminal still sends Windows-style key sequences. Added isWindowsTerminal() helper that checks for WSL_DISTRO_NAME and WSL_INTEROP environment variables.
|
I discovered an issue with the previous platform detection approach: WSL reports Updated the fix to also check for WSL environment variables:
This ensures Ctrl+Backspace works correctly for:
Tests updated to use the same detection logic. |
| import { parseKeypress, nonAlphanumericKeys, type ParsedKey, type KeyEventType } from "./parse.keypress" | ||
| import { Buffer } from "node:buffer" | ||
|
|
||
| const isWindowsTerminal = (): boolean => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tests should probably use the same method as parse.keypress if it's not mocking anything?
Summary
delete-word-backwardon Windows Terminal and WSLProblem
Windows Terminal and WSL terminals send different byte sequences for backspace:
\x7f(ASCII 127, DEL)\b(ASCII 8)The current parser treats both as plain backspace without setting
ctrl: true, so keybindings likectrl+backspace→delete-word-backwardnever trigger.Additional WSL Complexity
In WSL,
process.platformreturns'linux', not'win32', even though Windows Terminal sends Windows-style key sequences. This required detecting WSL via environment variables (WSL_DISTRO_NAME,WSL_INTEROP).Solution
Added
isWindowsTerminal()helper that detects:process.platform === 'win32')WSL_DISTRO_NAMEorWSL_INTEROPenvironment variables)\bHandling{ name: "backspace", ctrl: true }{ name: "h", ctrl: true }Testing
isWindowsTerminal()helper for platform-aware assertionsFixes anomalyco/opencode#6991