fix(ink): sync native cursor for CJK IME and optimize frame rendering#2297
Open
HUQIANTAO wants to merge 1 commit into
Open
fix(ink): sync native cursor for CJK IME and optimize frame rendering#2297HUQIANTAO wants to merge 1 commit into
HUQIANTAO wants to merge 1 commit into
Conversation
03576d9 to
ea21c20
Compare
a6405ab to
e41c69c
Compare
Problem: - CJK IME candidate popups appeared at wrong position (top-left) because the native terminal cursor was not synced to the visual input position - Custom ▌ cursor character animated left-to-right during IME composition because each keystroke triggered a separate re-render - Per-cell diff patches caused visible cursor movement on terminals without DEC 2026 (synchronized output) support Solution: - Export useDeclaredCursor hook from Ink and use it in PromptInput to park the native cursor at the visual input position (fixes IME popup alignment) - Skip redundant cursor declaration updates when position is unchanged (prevents jitter during IME preedit commit) - Optimize diff output: merge cursorMove+stdout patches and consecutive stdout patches in the optimizer (reduces per-cell rendering) - Always send BSU/ESU in inline mode for atomic frame rendering - Use native terminal cursor instead of custom ▌ character - Batch rapid input (IME pinyin + committed CJK) via setTimeout(0) so multiple keystrokes coalesce into a single re-render — the cursor jumps directly to the final position instead of moving per-character
e41c69c to
caf058f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
CJK IME candidate popups appeared at wrong position (top-left) because the native terminal cursor was not synced to the visual input position. The custom ▌ cursor character also animated left-to-right during IME composition because each keystroke triggered a separate re-render.
Solution
Cursor sync
useDeclaredCursorhook from Ink and use it inPromptInputto park the native cursor at the visual input position — fixes IME popup alignmentFrame rendering optimization
cursorMove+stdoutpatches and consecutivestdoutpatches in the optimizer — reduces per-cell renderingsetTimeout(0)so multiple keystrokes coalesce into a single re-render — the cursor jumps directly to the final positionFiles changed
packages/ink/src/components/App.tsx— stop hiding native cursorpackages/ink/src/hooks/use-declared-cursor.ts— add position-comparison guardpackages/ink/src/index.ts— exportuseDeclaredCursorpackages/ink/src/ink.tsx— always send BSU/ESU in inline modepackages/ink/src/optimizer.ts— merge consecutive stdout patchespackages/ink/src/terminal.ts— importcursorPositionsrc/cli/ui/PromptInput.tsx— cursor sync + input batching