Is there a straightforward way to have a Cmd
execute after the view is updated? In particular, I’m trying to reposition the cursor in a textarea
upon specific keys (like the enter key) being pressed. In my update
function I have:
case keyboardEvent.key of
"Enter" ->
( modelAfterEnterPressed model keyboardEvent.selectionStart, setCursor model.cursor )
"Tab" ->
....
My setCursor
port is called and the corresponding JavaScript code calls the textarea
‘s setSelectionRange
function properly. And then Elm calls my view
function which updates the textarea
‘s content. Unfortunately, that wipes out my cursor position.
I need for the textarea
‘s content to be updated before calling textarea.setSelectionRange()
in my JavaScript port. Any way to do this without resorting to setTimeout
which might not always work and can cause flashes within the timeout?