Ah, come back to fill the holes.
Same link: https://codesandbox.io/s/optimistic-hoover-5uuy2?file=/src/CodemirrorView.js
Welcome to test it.
If you find a bug or have some good ideas to improve the interaction, welcome to share it.
Some points when I try to bind codemirror6 with prosemirror.
- Don’t use history stack of codemirror. So we can’t directly use
@codemirror/basic-setup
. - When the content or selection of codemirror change, synchronize them to prosemirror. Check the
forwardSelection
andhandleValueChange
function. - When the codemirror lose focus, reset its selection to zero position.
- When execute
redo
orundo
, the changes will synchronize to codemirror through theupdate
method of CodemirrorView.
For this problem, we use a custom logic for press Backspace key. My logic is: set the codemirror node to paragraph node, then focus the view of prosemirror. (Check the backspace
method.)
Fixed by adding selection data to the changes.(Check the update
method.)
this.cm.dispatch({
changes: { from: change.from, to: change.to, insert: change.text },
// add selection
selection: { anchor: change.from + change.text.length }
});
But there are some limits. eg: The multiple selection can’t recover by
undo
action, because we use the history stack of prosemirror.
Don’t use.