Currently, there's no way of handling the selection API directly Elm. The way I've worked around this was by creating a webcomponent to track the current selection state, and using custom events to notify Elm of how the state has changed. I also used relative paths in the HTML to distinguish which elements were selected, and a custom Node type separate from the opaque Html/VirtualDom.Node type referenced in the Html module to resolve the selection. https://github.com/mweiss/elm-rte-toolkit/blob/1.0.1/js/elmEditor.js#L142
It would be nice if there were some way of keeping track of this in Elm directly without requiring a webcomponent, either with a global selection API in browser package that would keep track of this information, or with some limited support in Html.Events for a selection event that would give the selection state relative to the element.
Currently, there's no way of handling the selection API directly Elm. The way I've worked around this was by creating a webcomponent to track the current selection state, and using custom events to notify Elm of how the state has changed. I also used relative paths in the HTML to distinguish which elements were selected, and a custom Node type separate from the opaque
Html
/VirtualDom.Node
type referenced in theHtml
module to resolve the selection. https://github.com/mweiss/elm-rte-toolkit/blob/1.0.1/js/elmEditor.js#L142It would be nice if there were some way of keeping track of this in Elm directly without requiring a webcomponent, either with a global selection API in browser package that would keep track of this information, or with some limited support in
Html.Events
for a selection event that would give the selection state relative to the element.On the discourse, there was a similar proposal a few years ago: https://discourse.elm-lang.org/t/selection-api-for-elm/1351