fix(tui): handle emojis in input cursor (#1183)

This commit is contained in:
xu0o0 2026-02-03 01:03:57 +08:00 committed by GitHub
parent d0228412d6
commit fe534b2200
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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 : "";