Skip to content

Fix UTF-16 indexing for emoji characters in code storage - #140

Merged
mchakravarty merged 1 commit into
mchakravarty:mainfrom
adamwulf:fix/utf-16-emoji
Jan 12, 2026
Merged

Fix UTF-16 indexing for emoji characters in code storage#140
mchakravarty merged 1 commit into
mchakravarty:mainfrom
adamwulf:fix/utf-16-emoji

Conversation

@adamwulf

@adamwulf adamwulf commented Jan 6, 2026

Copy link
Copy Markdown
Contributor

Pressing Enter at the end of a document containing emoji characters (e.g., "flag: 🏁 fumble") causes a crash with "String index is out of bounds" in tokenCompletion(for:at:).

The index parameter is a UTF-16 offset (from NSRange), but the code was treating it as a Character offset: string.utf16[string.index(string.startIndex, offsetBy: index)]

Emojis like 🏁 are 1 Character but 2 UTF-16 code units, causing the index to exceed the string's character count.

I ran into this while building an app with your amazing library, thanks for your work!

@adamwulf adamwulf closed this Jan 8, 2026
@adamwulf
adamwulf deleted the fix/utf-16-emoji branch January 8, 2026 20:21
@adamwulf
adamwulf restored the fix/utf-16-emoji branch January 9, 2026 09:08
@adamwulf

adamwulf commented Jan 9, 2026

Copy link
Copy Markdown
Contributor Author

oops! I accidentally deleted the branch, which closed the PR 🙈

@adamwulf adamwulf reopened this Jan 9, 2026
@mchakravarty
mchakravarty merged commit 9b2bae8 into mchakravarty:main Jan 12, 2026
@mchakravarty

Copy link
Copy Markdown
Owner

Great catch! Thanks a lot and happy to hear that the library is helpful 😀

(Just curious: what kind of app are you building if you don't mind me asking?)

@awwright

awwright commented Aug 4, 2026

Copy link
Copy Markdown

Can you please tag this? I think this fixes a crash that occurs when adding a newline close to the end of the editor.

As for me, I'm using this to present an editor for ABNF, and show syntax errors and shadowed rule names and the like.

@mchakravarty

Copy link
Copy Markdown
Owner

@awwright Yes, you are right. I was pushing this out for too long. I just released 0.16.0.

As for me, I'm using this to present an editor for ABNF, and show syntax errors and shadowed rule names and the like.

Nice!

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.

3 participants