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

Feature: resolve x/y in text block to string char index #25

Closed
lojjic opened this issue Dec 9, 2019 · 1 comment
Closed

Feature: resolve x/y in text block to string char index #25

lojjic opened this issue Dec 9, 2019 · 1 comment

Comments

@lojjic
Copy link
Collaborator

lojjic commented Dec 9, 2019

This is a necessary feature for eventually enabling text selection/highlighting/editing.

We need the ability to raycast a position in a rendered text block, and for that position determine the closest character boundary to it, returning an index in the original text string.

It's easy enough to resolve the glyph index, by searching through the glyph rects array, but there isn't a clean way to resolve the glyph index back to string char index. These aren't always 1-to-1 due to ligature substitution etc. This may require modifying Typr.js to persist char indexes with the glyphs.

@lojjic
Copy link
Collaborator Author

lojjic commented Jan 10, 2020

This has been implemented in selectionUtils.js#getCaretAtPoint which resolves an x/y to the nearest caret position. The resulting caret object holds a charIndex property.

@lojjic lojjic closed this as completed Jan 10, 2020
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

1 participant