I’m trying to add an inline input (as a widget) to my editor, but struggling to accomplish various things. One of the main things I haven’t managed to sort out yet is getting the selection styling back so that you can actually see text you’ve selected. The cursor caret itself was easy to get back with style.caretColor, but something extra apparently is needed for pseudo-selectors. It is hard to demonstrate in the playground (as it is hard to add a pseudo-selector like this), but if you just add a
After a little digging, I have found that it is the presence of the drawSelection plugin which is breaking ::selection (which makes sense). Here is an updated repro to demonstrate:
Also another issue I’m having is how to make the <input /> autofocus when it is rendered. I can technically make it work by adding a setTimeout or requestAnimationFrame right before I return the DOM element in toDOM, but obviously I don’t want to actually do that.
The hideNativeSelection bit of drawSelection is the culprit. It targets the ::selection with !important not only for the .cm-line but for all (not even direct) children as well, which is the issue. Would it be possible to make it a little less aggressive, @marijn? Not sure what the broader implications are.
This patch disables those styles for nested focused elements, which should work here. Unfortunately, Chrome (at least on Linux) doesn’t seem to make it possible to revert to the default selection color (initial and revert styles don’t seem to do anything for ::selection).