I’m using codemirror inside of a React application (with this wrapper as a starting point: https://github.com/ForbesLindesay/react-code-mirror), which is working pretty well. I’m using it in ‘controlled’ mode (where a change in the props calls setValue on the underlying editor instance). One of the features of my program inserts text into the editor for you at the current cursor position, and after it does I’d like to retain the cursor position, but the call to setValue resets the selection to the beginning of the document.
Right now what I’m doing is grabbing and storing the selection value in every beforeSelectionChange event, which I then manipulate and call setSelection with, but beforeSelectionChange fires when setValue is called. Is there any way for me to tell that the cause was a setValue so I can ignore it? Or perhaps another approach I’m missing?