Re-render view on state.doc update

I’m using CM with Vue and its reactivity feature. So basically the doc I pass into the initial Editor state is reactive and updates automatically via Vue if there are changes from somewhere else.

Unfortunately, CM doesn’t update its view after reactive changes. Can I somehow trigger a manual re-render ot tell CM to watch for changes in its doc?

Or do I need to prepare and dispatch a Transaction?

Since I do not know the exact changes, but only the entire new doc string, the transaction would need to simply replace the entire doc of the state.

Is that possible with {changes: {from: 0, replace: myUpdatedDoc}}. I tried this, but CM throws an exception, telling me the originating state of the transaction does not match the current state. Probaby because of the reactivity of the doc which was updated internally, already?

Any tips or experiences on this would help me a lot.

That doesn’t really work — you’ll lose all kinds of state (selection, undo history, any extra stuff that exists in the documents) and waste a lot of cpu cycles (unnecessary redraws, reparses). You’ll have to arrange for any changes to dispatch transactions to the editor (using the correct start state, or just calling EditorView.dispatch, which should make it impossible to use the incorrect start state), and preferably diff the documents to derive a minimal change, if you really only have access to randomly updated documents with no known connection to the existing document.

Thanks for your quick reply.

Well, diffing prior to applying the changes is of course possible. However, I fear losing some robustness. Can you probably recommend any JS library that produces a diff capable of being the basis for CM change sets?