Maybe a stupid question, but I cannot find the answer how to apply a transform. The following line does not work (although I found this line in the answers of this discussion platform…), because you cannot apply a Transform directly. Does somebody know the answer HOW to apply a transform?
You should do something like this:
var newState = this.proseMirrorView.state.apply(transaction);
Using your example it would be:
const transaction = state.tr.insert(pos.end(), node);
Thanks for answering. But unfortunately, the method ‘apply’ expects a ‘Transaction’ object, not a ‘Transform’ object (although Transform is super-object from Transaction). The ‘.insert’ function returns a Transform object, unfortunately…
This is the error message I get:
error TS2345: Argument of type ‘Transform’ is not assignable to parameter of type ‘Transaction’.
Property ‘time’ is missing in type ‘Transform’.
It is working great for me. Here was my quick test:
var state = view.state;
var textNode = editor.state.doc.nodeAt(2);
// hacky clone method
var node = textNode.constructor.fromJSON(state.schema, textNode.toJSON());