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

UI - Input: Cursor should not shift text content #415

Closed
aweary opened this issue Mar 26, 2019 · 5 comments · Fixed by #419
Closed

UI - Input: Cursor should not shift text content #415

aweary opened this issue Mar 26, 2019 · 5 comments · Fixed by #419
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@aweary
Copy link

aweary commented Mar 26, 2019

2019-03-25 16 02 02

The issue seems to be that the cursor View is part of the normal content flow, so when it moves it also shifts the characters around. I checked oni2 and it doesn't have this problem since it uses absolute positioning for the cursor and manually calculates the offset. It seems like something similar should be done here for the Input component.

@bryphe bryphe added bug Something isn't working help wanted Extra attention is needed labels Mar 27, 2019
@bryphe
Copy link
Member

bryphe commented Mar 27, 2019

Thanks for the report & gif, @aweary! Confirmed on Windows - it seems like we're including the cursor in the text calculation (which is shifting the text).

@aweary
Copy link
Author

aweary commented Mar 27, 2019

@bryphe I’m happy to work on this if you can give a few code pointers to get started with 🙂

@akinsho
Copy link
Member

akinsho commented Mar 27, 2019

Would be great to have some help with the input 😍, at the moment the cursor is in the flow which causes this issue. We began discussing some of the ongoing issues with the input in #203. Something we haven't done yet is expose a way of finding out where a character is in the text which would allow us able to position the cursor absolutely

@bryphe
Copy link
Member

bryphe commented Mar 27, 2019

Definitely, would be awesome to have help @aweary ! 💯

Some ideas for starting out - this code here is important:

let (startStr, endStr) = getStringParts(cursorPosition, inputString);

(This is where we split the text and put a cursor in the middle).

We actually have an API to measure text size here:

let measure = (~fontFamily, ~fontSize, text) => {

Instead of rendering the cursor 'in the flow' - we could measure the startStr with this API (getting the fontFamily/fontSize, and the text which we already have with `startStr) - this would give us the size of the string before the cursor in pixels. Then, we could render the cursor absolutely positioned, out of the flow, based on the width of that measurement.

This will get a bit more complicated in the case of multi-line text, but I believe our inputs only handle the single-line case (something we'll have to think about as we extend them to support multi-line!).

@bryphe
Copy link
Member

bryphe commented Mar 30, 2019

Just a heads up @aweary - looks like @tatchi started this in #419 (don't want to duplicate work 😄 )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants