Since the content in your replacement widget has nothing to do with the CodeMirror document, there wouldn't be a meaningful way to represent such selections.
Not quite. It's useful to think of blocks as merely a different
Display component, and nobody would suggest that the lines or tokens in the
Display have nothing to do with the Document! The content inside the replacement widgets absolutely represent the CM document. The code:
(+ 1 2) will be replaced with one node representing the whole expression, and that node has three children representing
2. Modifying any one of those children will update the document.
So what happens if the user has clicked on (selected) the second child? Essentially, their "selection" is on the node representing
1. Now suppose the user changes that node (thereby updating the underlying CM content) and then navigates elsewhere, then realizes they made a mistake and hits Ctrl-Z. What should happen? Well, we'd like CM to revert back to the previous state (returning that node to
1), and we'd like to see that node re-selected (just as it was before the change).
Take a look at this demo, if the above description doesn't make sense. I'm using the CM value as the underlying data structure, and updating it whenever a node is changed, moved, created, or deleted.