Skip to content

Bug: Jumping cursor #158

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

Closed
MartinKavik opened this issue Jun 21, 2019 · 7 comments · Fixed by #289
Closed

Bug: Jumping cursor #158

MartinKavik opened this issue Jun 21, 2019 · 7 comments · Fixed by #289
Labels
bug Something isn't working

Comments

@MartinKavik
Copy link
Member

MartinKavik commented Jun 21, 2019

Test case:

  1. cargo make start counter
  2. Click to the input with text click - place cursor somewhere before the last letter, e.g. c|lick
  3. Write something (e.g. x) and observe - you should see cxlick|

I tried to reset master branch before we merged sync with animation frame but it seems that this bug was here from the beginning.

I was googling a little bit and it seems that every second person encountered this - jQuery, React, plain js..

I'll try to fix it somehow.

@MartinKavik
Copy link
Member Author

I investigated it a little bit, see referenced PR #159 for more info.
@David-OConnor I don't want to change code under your hands and I think that it will we more effective when you fix it while you are refatoctoring events & listeners.

@David-OConnor David-OConnor added the bug Something isn't working label Jun 30, 2019
@MartinKavik
Copy link
Member Author

@David-OConnor Do you have something in progress or can I fix it?

@David-OConnor
Copy link
Member

Have at it - Nothing on my end.

@MartinKavik
Copy link
Member Author

Bug seems to be fixed on desktop browsers (Firefox + Chrome on Windows), but it still jumps on iOS (Safari + Firefox). You can test it with https://seed-rs-realworld.netlify.com/ (for example on Sign-in form).

Possible solution is to remember cursor position before calling set_value and then set it to previous value (inspired by facebook/react#955 (comment)).
Or we can experiment with orders.force_render.

P.S. @David-OConnor I will be without PC for about two weeks in August, so I can't start working on it until the second half of August.

@MartinKavik MartinKavik reopened this Jul 25, 2019
@David-OConnor
Copy link
Member

That RWE looks great!

@MartinKavik
Copy link
Member Author

MartinKavik commented Oct 8, 2019

Update:
Can't use solution in facebook/react#955 (comment) now, because it's blocked by rustwasm/wasm-bindgen#1811.
Once this PR is merged and a new wasm-bindgen (web-sys) is released, we can continue to implement it probably here: https://github.com/David-OConnor/seed/blob/291c6392b452b99f56fc6a8095a42313c32dba5e/src/util.rs#L108 We have to be careful with implementation for HTMLInputElement because only some types support selectionStart/End - see table https://html.spec.whatwg.org/multipage/input.html#concept-input-apply.

How to test it:

  1. cargo make start counter
  2. open it on phone (bug exists at least on iOS + Firefox) - 192.168.x.x:8000
  3. write something to the only input field
  4. move cursor somewhere to the middle of the written text
  5. write something again
  6. observe: cursor shouldn't jump at the end of the text in the input

Update: PR merged, next web-sys version (> 0.3.28) should unblock implementation

@MartinKavik
Copy link
Member Author

Update: wasm-bindgen with required HTMLInputElement methods has been released: https://github.com/rustwasm/wasm-bindgen/releases/tag/0.2.52

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

Successfully merging a pull request may close this issue.

2 participants