Skip to content

Fix: Prevent stored buffer resend on backspace (#96)#98

Closed
pranav-n29 wants to merge 1 commit intoAOSSIE-Org:mainfrom
pranav-n29:buffer-fix
Closed

Fix: Prevent stored buffer resend on backspace (#96)#98
pranav-n29 wants to merge 1 commit intoAOSSIE-Org:mainfrom
pranav-n29:buffer-fix

Conversation

@pranav-n29
Copy link
Contributor

@pranav-n29 pranav-n29 commented Feb 16, 2026

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

  • Bug Fixes
    • Enhanced keyboard input handling with proper key press and release sequences
    • Refined text input validation for single character processing

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 16, 2026

📝 Walkthrough

Walkthrough

The 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

Cohort / File(s) Summary
Keyboard Input Handler
src/server/InputHandler.ts
Modified key handling to use explicit press/release sequences for mapped keys via KEY_MAP, with fallback to direct character typing for unmapped single characters. Restricted text input to single characters only instead of processing any text length.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A hop, a skip, a keyboard fix so fine,
Keys press and release, in perfect line,
No buffers linger when backspace strikes,
Just clean keystrokes, exactly as it likes!

🚥 Pre-merge checks | ✅ 6
✅ Passed checks (6 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: preventing stored buffer resend on backspace, which directly addresses the core issue being fixed.
Linked Issues check ✅ Passed The code changes modify key and text handling in InputHandler.ts to distinguish between key press/release semantics and character typing, which aligns with preventing unintended buffer resend on backspace.
Out of Scope Changes check ✅ Passed All changes are scoped to InputHandler.ts key and text handling logic, directly addressing the buffer resend issue without unrelated modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. The case 'key' block (and case 'text' below) uses different indentation from the rest of the switch — other cases are indented at 3 levels (12 spaces), while this block starts at 4 spaces. Please align with the surrounding code.

  2. Line 98: console.log on every key press is noisy for production. Consider removing it or gating it behind a debug flag.

The core logic change (using pressKey/releaseKey for mapped keys like Backspace instead of type()) 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;

Comment on lines +160 to +164
case 'text':
if (msg.text && msg.text.length === 1) {
await keyboard.type(msg.text);
}
break;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

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.

@imxade
Copy link
Contributor

imxade commented Feb 17, 2026

not a complete fix, first character is still being sent with backspace instead of instant deletion

@imxade imxade closed this Feb 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Previous input stays after injection

2 participants