Fix: Prevent stored buffer resend on backspace (#96)#98
Fix: Prevent stored buffer resend on backspace (#96)#98pranav-n29 wants to merge 1 commit intoAOSSIE-Org:mainfrom
Conversation
📝 WalkthroughWalkthroughThe InputHandler.ts now lowercases incoming keys, maps them to nut-keys via KEY_MAP, and sends explicit press/release sequences for mapped keys. Unmapped single characters are typed directly; others are logged. Text input is restricted to single characters only, replacing previous direct typing behavior. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 6✅ Passed checks (6 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/server/InputHandler.ts`:
- Around line 160-164: The current guard in InputHandler.ts inside the switch
case 'text' drops any multi-character msg.text when it checks length === 1;
change this to preserve paste/IME input by either removing the length check and
iterating over each character in msg.text and calling keyboard.type(char) for
each, or if you prefer to keep a guard, log a warning with the dropped msg.text
before discarding so it’s diagnosable; alternatively, fix the root client-side
issue (clear buffer on Backspace) and then remove this server-side restriction.
🧹 Nitpick comments (1)
src/server/InputHandler.ts (1)
96-113: Inconsistent indentation and leftover debug logging.Two things:
The
case 'key'block (andcase 'text'below) uses different indentation from the rest of theswitch— other cases are indented at 3 levels (12 spaces), while this block starts at 4 spaces. Please align with the surrounding code.Line 98:
console.logon every key press is noisy for production. Consider removing it or gating it behind a debug flag.The core logic change (using
pressKey/releaseKeyfor mapped keys like Backspace instead oftype()) correctly addresses the buffer resend bug.Proposed fix for indentation and debug log removal
- case 'key': - if (msg.key) { - console.log(`Processing key: ${msg.key}`); - const lowerKey = msg.key.toLowerCase(); - const nutKey = KEY_MAP[lowerKey]; - - if (nutKey !== undefined) { - await keyboard.pressKey(nutKey); - await keyboard.releaseKey(nutKey); - } - else if (msg.key.length === 1) { - await keyboard.type(msg.key); - } - else { - console.log(`Unmapped key: ${msg.key}`); - } - } - break; + case 'key': + if (msg.key) { + const lowerKey = msg.key.toLowerCase(); + const nutKey = KEY_MAP[lowerKey]; + + if (nutKey !== undefined) { + await keyboard.pressKey(nutKey); + await keyboard.releaseKey(nutKey); + } else if (msg.key.length === 1) { + await keyboard.type(msg.key); + } else { + console.warn(`Unmapped key: ${msg.key}`); + } + } + break;
| case 'text': | ||
| if (msg.text && msg.text.length === 1) { | ||
| await keyboard.type(msg.text); | ||
| } | ||
| break; |
There was a problem hiding this comment.
Restricting text to single characters silently drops multi-char input (e.g., paste, IME).
The length === 1 guard fixes the backspace buffer-resend symptom, but it also silently discards any legitimate multi-character text input such as clipboard paste or IME composition strings. This could confuse users when paste stops working.
Consider either:
- Logging when text is dropped so it's at least diagnosable, or
- Fixing the root cause on the client side (clearing the buffer on Backspace) rather than restricting server-side text length, or
- Iterating over each character in the text string individually if multi-char support is needed.
Minimal improvement: iterate over characters instead of dropping
case 'text':
- if (msg.text && msg.text.length === 1) {
- await keyboard.type(msg.text);
- }
- break;
+ if (msg.text && msg.text.length > 0) {
+ for (const char of msg.text) {
+ await keyboard.type(char);
+ }
+ }
+ break;This preserves paste/IME support while still typing character-by-character. If the real issue is duplicate sends from the client, the client-side buffer should be cleared on Backspace instead.
🤖 Prompt for AI Agents
In `@src/server/InputHandler.ts` around lines 160 - 164, The current guard in
InputHandler.ts inside the switch case 'text' drops any multi-character msg.text
when it checks length === 1; change this to preserve paste/IME input by either
removing the length check and iterating over each character in msg.text and
calling keyboard.type(char) for each, or if you prefer to keep a guard, log a
warning with the dropped msg.text before discarding so it’s diagnosable;
alternatively, fix the root client-side issue (clear buffer on Backspace) and
then remove this server-side restriction.
|
not a complete fix, first character is still being sent with backspace instead of instant deletion |
Fixes #96
When pressing Backspace, the previously stored input buffer was being re-sent before the deletion occurred. This caused:
Duplicate text to appear
Previous full message to be retyped
Noticeable delay before character deletion
Summary by CodeRabbit
Release Notes