I’m building a multi-view editor based on CodeMirror 6 (which is amazing and thanks for releasing it). I have several local CodeMirror views that are synchronised following the Split View example, although on the CodeMirror side I’ve rewritten the example’s syncDispatch
function to aggregate an array of Transactions into a TransactionSpec[]
of changes, because I read in the code that the single-transaction version of dispatchTransactions
is deprecated:
const syncDispatch = (trs: readonly Transaction[], view: EditorView,...) => {}
I’m now trying to synchronise the master CodeMirror instance with a ProseMirror view, following the Collab example.
I create the ProseMirror view:
// create prosemirror view, and bind to element
const view: PMEditorView = new PMEditorView( element as HTMLElement,{
state: PMEditorState.create({...}),
dispatchTransaction: transaction => customDispatch({type: "transaction", transaction}, view)
});
and set up its dispatch function:
const customDispatch = (action: any, local_view: PMEditorView) => {
const source = action.transaction.changes ? 'cm' : 'pm';
switch (source) {
case 'cm' :
const changes: TransactionSpec[] = action.transaction.changes;
// @todo merge in CodeMirror transaction
break;
case 'pm' :
// merge in ProseMirror transaction to update local view
local_view.updateState(local_view.state.apply(action.transaction));
// @todo create and dispatch CodeMirror transaction
break;
}
};
Could you offer any advice on how to translate between the CodeMirror and ProseMirror transactions please?
I understand that CodeMirror 6 is newer than ProseMirror, so I wonder if the former is indicative of the latter’s future direction. If so, might future versions of ProseMirror become more structure-compatible with CodeMirror 6? Mine is not an urgent requirement, so I could wait if this activity is prohibitively complex now, but will get easier at some point in the future?