Title: id(web): world keyboard encoder drops or silently degrades modified special keys — Alt+Backspace sends plain Backspace, Alt+Arrow is dropped to the browser · Issue #732 · developing-today/code · GitHub
Open Graph Title: id(web): world keyboard encoder drops or silently degrades modified special keys — Alt+Backspace sends plain Backspace, Alt+Arrow is dropped to the browser · Issue #732 · developing-today/code
X Title: id(web): world keyboard encoder drops or silently degrades modified special keys — Alt+Backspace sends plain Backspace, Alt+Arrow is dropped to the browser · Issue #732 · developing-today/code
Description: Summary terminalBytesForKey in pkgs/id/web/src/world-keyboard.ts handles modified special keys inconsistently: some are silently dropped, and the rest are silently degraded to the unmodified key — so a world application receives a plain ...
Open Graph Description: Summary terminalBytesForKey in pkgs/id/web/src/world-keyboard.ts handles modified special keys inconsistently: some are silently dropped, and the rest are silently degraded to the unmodified key — ...
X Description: Summary terminalBytesForKey in pkgs/id/web/src/world-keyboard.ts handles modified special keys inconsistently: some are silently dropped, and the rest are silently degraded to the unmodified key — ...
Opengraph URL: https://github.com/developing-today/code/issues/732
X: @github
Domain: github.com
IPv4 address: 140.82.112.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"id(web): world keyboard encoder drops or silently degrades modified special keys — Alt+Backspace sends plain Backspace, Alt+Arrow is dropped to the browser","articleBody":"## Summary\n\n`terminalBytesForKey` in `pkgs/id/web/src/world-keyboard.ts` handles modified special keys inconsistently: some are silently dropped, and the rest are silently degraded to the *unmodified* key — so a world application receives a plain Backspace / Enter / Delete that the user never pressed, while other modified keys vanish entirely.\n\n## Evidence (verified on main `5db60876`)\n\nThe special-key branch (`world-keyboard.ts:36-40`):\n\n```ts\nif (event.key in specialKeys) {\n if ((event.ctrlKey || event.altKey || event.shiftKey) && event.key.startsWith(\"Arrow\")) return null;\n if (event.shiftKey && event.key === \"Tab\") return null;\n return new TextEncoder().encode(specialKeys[event.key]);\n}\n```\n\nOnly modified arrows and Shift-Tab are rejected; every other modifier combination falls through to the plain sequence. A temporary vitest probe driving the real function (removed after the run) produced:\n\n| Input | Result | Plain-key result |\n|---|---|---|\n| Alt+Backspace | `\\x7f` | `\\x7f` (identical) |\n| Ctrl+Backspace | `\\x7f` | `\\x7f` (identical) |\n| Alt+Enter | `\\r` | `\\r` (identical) |\n| Alt+Tab | `\\t` | `\\t` (identical) |\n| Alt+Escape | `\\x1b` | `\\x1b` (identical) |\n| Ctrl+Delete | `\\x1b[3~` | `\\x1b[3~` (identical) |\n| Alt+Delete | `\\x1b[3~` | `\\x1b[3~` (identical) |\n| Ctrl+Home | `\\x1b[H` | `\\x1b[H` (identical) |\n| Shift+End | `\\x1b[F` | `\\x1b[F` (identical) |\n| Alt+PageUp | `\\x1b[5~` | `\\x1b[5~` (identical) |\n| Alt+ArrowUp | `null` (dropped) | `\\x1b[A` |\n| Alt+ArrowLeft | `null` (dropped) | `\\x1b[D` |\n| Shift+Tab | `null` (dropped) | `\\t` |\n\nContrast with printable keys in the same function: Alt+`x` correctly returns `\\x1bx` — the Alt modifier *is* preserved (as an ESC prefix) for printable input, just not for special keys.\n\n## Why it matters\n\n- **Wrong input delivered:** Alt+Backspace is word-delete in most editing contexts; the world app instead receives a single-character Backspace. Ctrl+Delete, Alt+Enter, Shift+End etc. all lose their modifier the same way. The caller in `pkgs/id/web/src/world.ts` (keydown handler, ~line 240) calls `preventDefault()` whenever bytes are returned, so the browser's own handling is suppressed and the degraded byte sequence is the *only* thing that happens.\n- **Dropped input leaks to the browser:** when the function returns `null`, the caller does not `preventDefault()`. Alt+ArrowLeft / Alt+ArrowRight are browser history navigation in several browsers, so a user trying to send a modified arrow to the world can instead navigate away from the world page mid-session.\n- **The decoder's design says nothing should be dropped or misreported:** the receiving side, `Key.parse` in `pkgs/id/examples/roc-world/Key.roc`, has no modified-key variants, but it deliberately surfaces unrecognised escape sequences as `Unknown(bytes)` (\"nothing is dropped\") — e.g. its own test pins `Key.parse(\"\\u(1b)[1;5C\") == [Unknown(\"\\u(1b)[1;5C\")]` for Ctrl+Right. The web encoder is the side that breaks that contract, in two opposite ways at once.\n\n## Suggested directions (one consistent policy)\n\nPick one and apply it to *all* special keys, not just arrows/Tab:\n\n1. **Encode the modifier** using the standard xterm modifier parameter (`;2`=Shift, `;3`=Alt, `;5`=Ctrl, …) for CSI sequences (`\\x1b[3;5~` Ctrl+Delete, `\\x1b[1;3A` Alt+Up, `\\x1b[Z` for Shift-Tab) and the ESC-prefix convention the function already uses for Alt+printable where a CSI form doesn't exist (ESC+`\\x7f` for Alt+Backspace). `Key.parse` will surface these as `Unknown` today — preserved, not misreported — and a later `Key` extension can name them.\n2. **Or return `null` consistently** for every modified special key the Roc `Key` module cannot represent, so no modified press is ever silently rewritten as the plain key — and document that modified specials are unsupported (accepting that the browser keeps e.g. Alt+Left).\n\nOption 1 matches the decoder's nothing-dropped contract; option 2 is the smaller change. Either is better than the current split.\n\n## Acceptance criteria\n\n- [ ] One documented policy covers every (special key × modifier) combination in `terminalBytesForKey`; no modified special returns the plain key's bytes, and the arrow/Shift-Tab special cases are no longer exceptions to a different rule.\n- [ ] Regression tests in `world-keyboard.test.ts` pin the policy for at least: Alt+Backspace, Ctrl+Delete, Alt+Enter, Shift+Home/End, Alt+PageUp, Alt+Arrow, Shift+Tab — and the existing plain and Alt+printable expectations still pass.\n- [ ] If option 1 is chosen, the emitted sequences are the standard xterm forms, and the `Key.roc` behaviour for them (currently `Unknown`) is noted in the PR.\n- [ ] Unmodified special keys, control letters, and AltGr (Ctrl+Alt printable) behaviour are unchanged.\n","author":{"url":"https://github.com/dezren39","@type":"Person","name":"dezren39"},"datePublished":"2026-10-24T08:42:02Z","url":"https://github.com/developing-today/code/issues/732"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:6b6c7724-d054-9ba2-737d-6e414004fc52 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B7E0:39ABD:80D077:AC7E2B:6B06345E |
| html-safe-nonce | 7c919391013f8f1731a968424e4222244b88957edab3f0f411926f040568be68 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCN0UwOjM5QUJEOjgwRDA3NzpBQzdFMkI6NkIwNjM0NUUiLCJ2aXNpdG9yX2lkIjoiODgxNzA1ODA5NTExMDE3Mzc5MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 44a075ed603fc23754225690fd710b8ce3e27e451e2ad86c9a26228333b59feb |
| hovercard-subject-tag | issue:6011134592 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/developing-today/code/732/issue_layout |
| twitter:image | https://opengraph.githubassets.com/491c5565e31cd45224f30262cd1b515afd4e901bd536bdd25d0078ad518c38ae/developing-today/code/issues/732 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/491c5565e31cd45224f30262cd1b515afd4e901bd536bdd25d0078ad518c38ae/developing-today/code/issues/732 |
| og:image:alt | Summary terminalBytesForKey in pkgs/id/web/src/world-keyboard.ts handles modified special keys inconsistently: some are silently dropped, and the rest are silently degraded to the unmodified key — ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dezren39 |
| hostname | github.com |
| expected-hostname | github.com |
| None | c3584c853cd39700ecff6e2cf8364295ffdb5313e571046c41cd2479270f7df0 |
| turbo-cache-control | no-preview |
| go-import | github.com/developing-today/code git https://github.com/developing-today/code.git |
| octolytics-dimension-user_id | 26439447 |
| octolytics-dimension-user_login | developing-today |
| octolytics-dimension-repository_id | 627308783 |
| octolytics-dimension-repository_nwo | developing-today/code |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 627308783 |
| octolytics-dimension-repository_network_root_nwo | developing-today/code |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 9eb3bb1597d09170a5f282cd38ae376dee1a5ec1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width