-
Notifications
You must be signed in to change notification settings - Fork 22
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
In input controls, cursor sporadically jumps to the end of text while typing #220
Comments
I have seen this a lot, and not only with Websharper. It happens when there is significant processing happening between keystrokes.
|
A possible lead would be to add to |
@Tarmil I think it might be possible to avoid enhancing FWIW, here's a rather inelegant "user land" approach that employs a mutable to keep track of the last known input value (helper functions included for completeness):
|
Sorry, our CI system closed this by mistake when we implemented a temporary workaround in our project. Reopening. |
Okay, so here's something interesting. I tried your solution, and it seems to be working correctly; I have never seen the cursor jump with it. However, when I change it slightly to use let Input3 attrs var =
let mutable expectedValue = ""
let onChange el _ =
expectedValue <- el?value
var |> Var.setIfChanged expectedValue
let updateElement el v =
if v <> expectedValue
then el?value <- v
let changeHandlers = [
Attr.DynamicCustom updateElement var.View
on.change onChange
on.input onChange
on.keyPress onChange ]
Elt.input (Seq.append attrs changeHandlers) [] then I can see the cursor jump again. So it looks like there is actually a bug somewhere in the propagation of Views to Attrs. |
@Tarmil That is interesting! When I implemented the workaround I introduced the check against Your finding made me wonder if the workaround I posted would function without the mutable (since the salient change may have been in fact avoiding the View -> Attr propagation). So, I tried removing let Input attrs var =
let onChange el _ =
var |> Var.setIfChanged expectedValue
let changeHandlers = [
on.change onChange
on.input onChange
on.keyPress onChange ]
let input = Elt.input (Seq.append attrs changeHandlers) []
let updateElement v =
if v <> input.Dom?value
then input.Dom?value <- v
Doc.Concat [ input; Sink updateElement var.View ] So yes, it looks like the root cause of the issue may indeed be a bug in the propagation of Views to Attrs |
Yes, and in fact this equality check is already implemented in the library, just in an Attr 🙂 ui/WebSharper.UI/Attr.Client.fs Line 299 in 4c641b9
|
Oh, I remember something related, from 6 years ago 🙂 : #2 |
Some progress on this, I found that it's not quite a bug in the propagation, but rather the fact that the check-and-set is not done at the same time in both versions. With I have a small proof of concept to do the equality check in a |
Fix #220: in value Attrs, check equality during View propagation
Repro steps (successfully reproduced in in Chrome, Edge, FireFox):
END
Result: The cursor jumps at the end of the text, resulting in incorrect input.
The issue seems to be caused by the logic used to update the input value, which incorrectly assumes that a change in Var value was caused by external factors, when in fact:
See video below:
Try.Websharper.and.9.more.pages.-.Personal.-.Microsoft.Edge.2021-07-15.17-32-31.mp4
The text was updated successfully, but these errors were encountered: