Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getCaretAtPoint(...) taking surrogate pairs into consideration #304

Open
kalegd opened this issue Feb 7, 2024 · 2 comments
Open

getCaretAtPoint(...) taking surrogate pairs into consideration #304

kalegd opened this issue Feb 7, 2024 · 2 comments

Comments

@kalegd
Copy link

kalegd commented Feb 7, 2024

Currently getCaretAtPoint(...) does not take surrogate pairs into consideration. So if an emoji is present, the caret index found might be in the middle of it as emojis can span a variable number of code units (Attaching a gif to show an example of what I mean)

What are your thoughts on the function only returning the indices before or after the whole surrogate pair and not the middle ones in the case of emojis/other complex characters?

This is definitely an edge case that could be handled on the client side, but I do think in the long run it would beneficial to have this support out of the box. I personally can't think of any reason one would want the index in the middle of some surrogate pair

@lojjic
Copy link
Collaborator

lojjic commented Feb 7, 2024

You're definitely right. The behavior you're showing is appropriate(ish) for ligature glyphs, but not for surrogates. I think we can add a check here for whether the indices were skipped due to ligatures vs. surrogates. We may also need to make some other adjustments in selectionUtils to make sure we walk back to the start of a surrogate and never return an inter-character index.

@kalegd
Copy link
Author

kalegd commented Feb 8, 2024

Great. Assuming no one else gets to it by then, I can put some time aside to work on a PR for it towards the end of the month

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

No branches or pull requests

2 participants