elm / virtual-dom

The foundation of HTML and SVG in Elm.
https://package.elm-lang.org/packages/elm/virtual-dom/latest
BSD 3-Clause "New" or "Revised" License
209 stars 80 forks source link

Set value property before selectionEnd and selectionStart #157

Open drathier opened 5 years ago

drathier commented 5 years ago

Changing the value property of a textarea also implicitly changes (step 4) its selectionEnd and selectionStart properties. Since virtual-dom isn't aware of this, the in-memory copy of the dom now differs from the real dom in these properties, leading to bugs.

Adding the logic to handle this properly requires handling a lot of edge cases, so I couldn't find a nice way to implement it considering that these properties are uncommon and code size is important, hence this hotfix.

This hotfix always considers the selectionStart and selectionEnd properties modified, like we already do with value and checked. Setting these properties to themselves (moving the cursor/selection to where it already is) is idempotent so this should be safe.

I've tested this patch by modifying the js output by the compiler. I've looked through the html spec; there doesn't seem to be other properties being implicitly modified.

rupertlssmith commented 1 year ago

Is there an Ellie or other example we can try this out on?

rupertlssmith commented 1 year ago

Its not clear what issue this PR actually solves. Is there an issue this can be linked to, or can you provide a little more explanation here?