Skip to content

fix(cli): remove quote-based drag detection to prevent input lag#2837

Merged
tanzhenxin merged 1 commit intoQwenLM:mainfrom
euxaristia:fix/quote-input-lag
Apr 5, 2026
Merged

fix(cli): remove quote-based drag detection to prevent input lag#2837
tanzhenxin merged 1 commit intoQwenLM:mainfrom
euxaristia:fix/quote-input-lag

Conversation

@euxaristia
Copy link
Copy Markdown
Contributor

TLDR

Fixes significant input lag when typing single quote (') and double quote (") characters by removing the quote-based drag-and-drop detection mechanism. The previous implementation delayed broadcasting quote characters by 100ms, causing noticeable lag during normal typing. Modern terminals use bracketed paste mode for file drag-and-drop, making the quote-based heuristic unnecessary.

Dive Deeper

Root Cause

The KeypressContext had a quote-based drag-and-drop detection mechanism that:

  1. Detected when a quote character was typed
  2. Buffered the character for 100ms waiting to see if more characters followed (indicating a file path from drag-and-drop)
  3. Only then broadcast the character

This caused a 100ms delay on every quote keystroke, which is very noticeable during typing.

The Fix

Removed the quote-based drag detection entirely because:

  • Modern terminals use bracketed paste mode (PASTE_MODE_PREFIX = ESC[200~) for file drag-and-drop operations
  • The bracketed paste handling is already implemented and working correctly
  • The quote-based heuristic was a fallback for legacy terminals that compromised the typing experience for all users

Changes

  • Removed quote character special handling (SINGLE_QUOTE, DOUBLE_QUOTE detection)
  • Removed unused drag-related refs and timers (isDraggingRef, dragBufferRef, draggingTimerRef)
  • Removed drag cleanup code on exit
  • Updated tests to reflect new behavior (quotes broadcast immediately)
  • Total: ~75 lines of code removed

Impact

Eliminates input lag when typing quotes and all other characters
Maintains drag-and-drop support via bracketed paste mode (modern terminals)
Cleaner, simpler code with less complexity
⚠️ Legacy terminals that don't support bracketed paste for file drops may need to use Ctrl+V for pasting file paths (this is already supported)

Reviewer Test Plan

  1. Pull and run the code: bun install && bun start
  2. Type messages containing single and double quotes:
    • It's working!
    • echo "hello world"
    • const x = 'test';
  3. Verify quotes appear immediately without any lag
  4. Test file drag-and-drop (if your terminal supports it):
    • Drag a file into the terminal window
    • The file path should still appear correctly via bracketed paste mode
  5. Run tests: bun test

Testing Matrix

🍏 macOS 🪟 Windows 🐧 Linux
npm run
npx
Docker
Podman -

Tested on Linux with bun - quotes now appear instantly with no lag.

Linked issues / bug

Fixes input lag when typing quote characters (no existing issue filed)

The previous implementation delayed broadcasting quote characters by 100ms
to detect file drag-and-drop operations. This caused noticeable input lag
when typing quotes, significantly impacting the typing experience.

Modern terminals use bracketed paste mode (PASTE_MODE_PREFIX) for file
drag-and-drop, which is already properly handled. The quote-based heuristic
was an unnecessary fallback that compromised responsiveness.

Changes:
- Remove quote character special handling in KeypressContext
- Remove unused drag-related refs and timers
- Remove drag cleanup code on exit
- Update tests to reflect immediate quote broadcasting

Impact:
- Eliminates input lag when typing quotes and other characters
- Maintains drag-and-drop support via bracketed paste mode
- Reduces code complexity (~75 lines removed)
- Legacy terminals without bracketed paste may need Ctrl+V for file paths

Fixes: input lag when typing single quote (') and double quote (") characters

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
@tanzhenxin tanzhenxin merged commit cf5c1ab into QwenLM:main Apr 5, 2026
13 checks passed
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.

2 participants