Cursor in wrong position for last character


I’m trying to create a kind of rich text editor where users can enter widgets besides plain text. For this, I’m replacing some codes in the text with dom nodes, Later I mount react component in those nodes and call editor.refresh. But after that, the cursor gets to a wrong position. It gets fixed when a new character is entered.

Here is a demo, I expect the cursor to be at the end of the line initially, but it is in the middle of the widget

The demo doesn’t load, but it looks like, after starting the asynchronous React renders, you immediately (synchronous) call refresh, before they had time to finish.

(Also, calling .changed() on the value returned by markText when its size changed is cheaper than a full editor refresh.)

Using .changed instead of refresh solved the problem, thanks :slight_smile: