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

Cursor at the end of the Text #78

Closed
arpu opened this issue Sep 20, 2020 · 8 comments
Closed

Cursor at the end of the Text #78

arpu opened this issue Sep 20, 2020 · 8 comments

Comments

@arpu
Copy link

arpu commented Sep 20, 2020

Hey,

working on a basic Cursor blinking at the End of the Text, any Idea what i should do if the maxWidth wrap the Text?
( using totalBlockSize )
( attached small showcast Video)

Peek 2020-09-20 10-06

@lojjic
Copy link
Collaborator

lojjic commented Sep 20, 2020

@arpu You should use the utility functions for caret and selection positioning described here: https://github.com/protectwise/troika/blob/master/packages/troika-three-text/README.md#carets-and-selection-ranges

Something like: add a listener for the synccomplete event, and in its handler call getSelectionRects passing the string length for both start and end. That should give you back a zero-width rectangle for placing the caret.

And then of course as you improve your text editor you can get caret positions at any place within the string as well. And selection rects too. :)

@arpu
Copy link
Author

arpu commented Sep 20, 2020

wau, thx for your fast response! this works fantastic!

@arpu arpu closed this as completed Sep 20, 2020
@arpu arpu reopened this Feb 17, 2021
@arpu
Copy link
Author

arpu commented Feb 17, 2021

@lojjic not sure if this is a bug or a problem on my side, but the getSelectionRects is not updated for a space in the first Line

Peek.2021-02-17.15-42.mp4

@arpu
Copy link
Author

arpu commented Feb 17, 2021

all works fine in the second line i get the right position with

 const catBox = getSelectionRects(e.target._textRenderInfo, 0 , this.data.value.length )
 right = catBox[catBox.length-1].right

@lojjic
Copy link
Collaborator

lojjic commented Feb 17, 2021

Hmm, it looks like getSelectionRects clips the rects to the overall bounds of the rendered glyphs, which may explain what you're seeing. I'll have to give some thought to whether that's the behavior we want or not (I think probably not, but need to make sure.)

In the meantime, you could maybe work around it by accessing textRenderInfo.caretPositions directly?

@lojjic
Copy link
Collaborator

lojjic commented Feb 17, 2021

Ah I see why I included that clipping, it's to avoid ugly things like this where the selection pokes out the right edge:

image

But I think it's the wrong approach for handling that, it needs to be smarter. I'll work on it.

lojjic added a commit that referenced this issue Feb 17, 2021
…hitespace

Fixes issue described in #78. We were clipping to the blockBounds, which
broke caret positioning for trailing whitespace. Removed that clipping
and added a different fix for overly wide trailing whitespace characters
when justifying.
@lojjic
Copy link
Collaborator

lojjic commented Feb 17, 2021

@arpu I've just released a 0.39.1 patch version which I think should fix your issue. Please let me know whether it works.

@arpu
Copy link
Author

arpu commented Feb 17, 2021

@lojjic wau! this fixed it for me! thx a lot for fast response!

@arpu arpu closed this as completed Feb 17, 2021
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