mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-10-06 15:39:41 +02:00
fix(shortcuts): stop Alt/Option nav keys leaking ESC sequences into the terminal
The PR migrated the app.js tab-nav handler to physical e.code but left xterm's pass-through gate (terminal-ui.js) matching ev.key digits. Consequences: - Alt+[ / Alt+] (the new bindings) were never in the gate, so xterm sent ESC[ / ESC] to the PTY on every platform AS WELL AS switching the session. - Alt+digit on a remapped macOS Option layout (Option+1 -> "¡") didn't match the ev.key '0'-'9' gate either, so xterm injected ESC<char> — on exactly the layouts this PR exists to fix. Update the xterm gate to mirror app.js exactly: suppress when `ev.altKey && !ctrl && !shift && /^(Digit[1-9]|BracketLeft|BracketRight)$/.test(ev.code)`. Returning false there tells xterm not to write to the PTY, so the shortcut switches the tab with no stray escape sequence. Also: relabel the docs Alt/Option (the mechanism is layout/OS-independent, so the shortcut works for Linux/Windows Alt users too — "Option" alone was Mac-only wording), and add a keyboard-shortcuts test asserting terminal-ui.js gates on the same physical codes so this desync can't regress (a grep the original test missed). Verified: keyboard-shortcuts test 4/4, check:frontend-syntax, check:public-assets, format:check all clean. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@ import { readFileSync } from 'node:fs';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
const appSource = readFileSync('src/web/public/app.js', 'utf8');
|
||||
const terminalUiSource = readFileSync('src/web/public/terminal-ui.js', 'utf8');
|
||||
const helpHtml = readFileSync('src/web/public/index.html', 'utf8');
|
||||
const readme = readFileSync('README.md', 'utf8');
|
||||
|
||||
@@ -19,11 +20,18 @@ describe('keyboard shortcuts', () => {
|
||||
expect(appSource).toContain('this.nextSession()');
|
||||
});
|
||||
|
||||
it('documents mac-friendly Option shortcuts in help and README', () => {
|
||||
expect(helpHtml).toContain('<kbd>Option</kbd>+<kbd>[</kbd>');
|
||||
expect(helpHtml).toContain('<kbd>Option</kbd>+<kbd>]</kbd>');
|
||||
expect(helpHtml).toContain('<kbd>Option</kbd>+<kbd>1-9</kbd>');
|
||||
expect(readme).toContain('`Option+[` / `Option+]`');
|
||||
expect(readme).toContain('`Option+1`-`Option+9`');
|
||||
it('suppresses xterm PTY injection for the same physical Alt nav codes (no ESC leak)', () => {
|
||||
// terminal-ui.js must gate its xterm pass-through on the SAME physical e.code set the
|
||||
// app.js handler consumes; otherwise Alt+[ / Alt+] (and Option+digit on remapped macOS
|
||||
// layouts) switch tabs AND inject ESC<char> into the focused terminal. Keep in sync.
|
||||
expect(terminalUiSource).toContain('/^(Digit[1-9]|BracketLeft|BracketRight)$/.test(ev.code');
|
||||
});
|
||||
|
||||
it('documents the Alt/Option shortcuts in help and README', () => {
|
||||
expect(helpHtml).toContain('<kbd>Alt/Option</kbd>+<kbd>[</kbd>');
|
||||
expect(helpHtml).toContain('<kbd>Alt/Option</kbd>+<kbd>]</kbd>');
|
||||
expect(helpHtml).toContain('<kbd>Alt/Option</kbd>+<kbd>1-9</kbd>');
|
||||
expect(readme).toContain('`Alt/Option+[` / `Alt/Option+]`');
|
||||
expect(readme).toContain('`Alt/Option+1`-`Alt/Option+9`');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user