fix: address 7 issues found in xterm-zerolag-input audit

1. Regex global flag safety — strip `g` flag before matching to prevent
   lastIndex mutation and missing .index on match results
2. state.visible false before activate — null overlay no longer reports
   visible: true
3. removeChar() returns 'pending' | 'flushed' | false instead of boolean
   so consumers can distinguish whether to send backspace to PTY
4. removeChar() implements buffer detection cascade (step 3) — detects
   existing prompt text when both pending and flushed are empty
5. RenderKey includes text content, not just length — prevents stale
   renders when setFlushed() called with same count but different text
6. Remove dead `import type { Terminal }` from test file
7. Remove internal `FontStyle` from public exports

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
arkon
2026-02-22 10:24:03 +01:00
co-authored by Claude Opus 4.6
parent d14ac9de65
commit 53132e3a38
6 changed files with 94 additions and 24 deletions
+3 -3
View File
@@ -40,8 +40,8 @@ terminal.onData((data) => {
zerolag.clear();
ws.send(text + '\r');
} else if (data === '\x7f') {
const removed = zerolag.removeChar();
if (removed) ws.send(data);
const source = zerolag.removeChar();
if (source === 'flushed') ws.send(data); // only backspace text already in PTY
} else if (data.length === 1 && data.charCodeAt(0) >= 32) {
zerolag.addChar(data);
// Don't send to server yet — wait for Enter
@@ -115,7 +115,7 @@ Implements xterm.js `ITerminalAddon`. Load via `terminal.loadAddon(addon)`.
|--------|-------------|
| `addChar(char)` | Add a single printable character to the overlay |
| `appendText(text)` | Append multiple characters (e.g., paste) |
| `removeChar(): boolean` | Remove last char. Returns `false` if nothing to remove |
| `removeChar(): 'pending' \| 'flushed' \| false` | Remove last char. Returns source (`'pending'` = unsent, `'flushed'` = send backspace to PTY) or `false` |
| `clear()` | Clear all state and hide overlay |
#### Flushed Text Tracking