From fe534b22003a19beb4174d780e1b566671e63c3c Mon Sep 17 00:00:00 2001 From: xu0o0 Date: Tue, 3 Feb 2026 01:03:57 +0800 Subject: [PATCH] fix(tui): handle emojis in input cursor (#1183) --- packages/tui/src/components/input.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/tui/src/components/input.ts b/packages/tui/src/components/input.ts index 369ea2fb..99ae2b78 100644 --- a/packages/tui/src/components/input.ts +++ b/packages/tui/src/components/input.ts @@ -307,9 +307,12 @@ export class Input implements Component, Focusable { // Build line with fake cursor // Insert cursor character at cursor position + const graphemes = [...segmenter.segment(visibleText.slice(cursorDisplay))]; + const cursorGrapheme = graphemes[0]; + const beforeCursor = visibleText.slice(0, cursorDisplay); - const atCursor = visibleText[cursorDisplay] || " "; // Character at cursor, or space if at end - const afterCursor = visibleText.slice(cursorDisplay + 1); + const atCursor = cursorGrapheme?.segment ?? " "; // Character at cursor, or space if at end + const afterCursor = visibleText.slice(cursorDisplay + atCursor.length); // Hardware cursor marker (zero-width, emitted before fake cursor for IME positioning) const marker = this.focused ? CURSOR_MARKER : "";