Repository navigation
fix(core): keep astral characters whole in multi-line input - #641
Open
kuldeepsinh19 wants to merge 4 commits into
Open
kuldeepsinh19 wants to merge 4 commits into
kuldeepsinh19 wants to merge 4 commits into
Conversation
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 detectedLatest commit: 482dde2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
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 |
commit: |
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.
What does this PR do?
MultiLinePromptkeeps 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:
Nothing changes for other text, and no snapshots change.
findTextCursoris untouched.5f27460) and pass with the fix. Undoing each source edit on its own makes at least one of them fail.a, Tab, Enter tomultiline({ 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.pnpm test(810 passed),pnpm types,pnpm depsandpnpm exec biome checkpass.Closes #640
Type of change
Checklist
pnpm testpasses (or targeted tests for my change)pnpm formathas been runAI-generated code disclosure