Skip to content

fix(core): keep astral characters whole in multi-line input - #641

Open
kuldeepsinh19 wants to merge 4 commits into
bombshell-dev:mainfrom
kuldeepsinh19:fix/multiline-astral-characters
Open

kuldeepsinh19 wants to merge 4 commits into
bombshell-dev:mainfrom
kuldeepsinh19:fix/multiline-astral-characters

Conversation

@kuldeepsinh19

Copy link
Copy Markdown
Contributor

What does this PR do?

MultiLinePrompt keeps its own cursor as a UTF-16 index and moves it one code unit at a time. An emoji arrives as one keypress holding two code units, so the cursor ended up between its halves: the next key was inserted inside the emoji, Enter twice stopped submitting, and Backspace, Delete and the arrow keys cut it in half. #640 has the repro.

This PR treats a surrogate pair as one character in the editor:

  • inserting advances the cursor by the length of what was inserted;
  • Backspace and Delete remove both halves;
  • the arrow keys step over the pair instead of stopping inside it;
  • the cursor highlight covers both halves.

Nothing changes for other text, and no snapshots change. findTextCursor is untouched.

  • The six new tests fail on main (5f27460) and pass with the fix. Undoing each source edit on its own makes at least one of them fail.
  • Feeding the raw bytes of 👍, then a, Tab, Enter to multiline({ showSubmit: true }) returns "\ud83da\udc4d" on 1.9.0 and "👍a" with this branch. 👍, Enter, Enter never submits on 1.9.0 and returns "👍" here.
  • Node 24.22.1: pnpm test (810 passed), pnpm types, pnpm deps and pnpm exec biome check pass.

Closes #640

Type of change

  • Bug fix
  • Feature
  • Refactor (no behavior change)
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

  • pnpm test passes (or targeted tests for my change)
  • pnpm format has been run
  • I have added/updated tests for my changes (if applicable)
  • I have added a changeset

AI-generated code disclosure

  • This PR includes AI-generated code

An emoji or other astral character arrives as one keypress holding two
UTF-16 code units, but the cursor moved forward by one. It was left
between the two halves, so the next key was inserted inside the
character and a double return could no longer submit.
…ters

The arrow keys moved one UTF-16 code unit at a time, so the cursor could
stop between the two halves of an emoji, and the cursor highlight
covered only one half. Step over the whole character and highlight both
halves.
Backspace and delete removed one UTF-16 code unit, which left half of an
emoji in the value. Remove both halves when the character next to the
cursor is a surrogate pair.
@changeset-bot

changeset-bot Bot commented Nov 17, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 482dde2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@clack/core Patch
@clack/prompts Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Nov 17, 2026

Copy link
Copy Markdown

commit: 482dde2

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] multiline splits emoji and other astral characters (corrupt value, Enter twice stops submitting)

1 participant