Hello, guys, I create prosemirror plugin and use it in tiptap editor in Vue3. The point is that when I delete a character in view[PluginView] → update I want to set a value in the meta and then read it in appendTransaction. If I do this and call view.dispatch( tr ) at the end I get an error RangeError: Applying a mismatched transaction
.
Here is the code:
export const testPlugin = () =>
{
return new Plugin(
{
key: new PluginKey('testPlugin'),
state:
{
init: () => ({bodyHeight: 5}),
apply: (tr, prev) =>
{
let next = { ...prev };
const bodyHeight = tr.getMeta('bodyHeight');
next.bodyHeight = bodyHeight;
return next;
}
},
view : () =>
{
return {
update: ( view, prevState ) =>
{
if( view.state.doc.eq( prevState.doc ) ){ return; }
const { selection, schema, tr } = view.state;
let deleting = false;
if(selection.$anchor.node(2) && prevState.selection.$anchor.node(2))
{
deleting = tr.doc.nodeSize < prevState.doc.nodeSize;
}
if( deleting )
{
view.dispatch( tr.setMeta('bodyHeight', 100 ) );
}
}
}
},
appendTransaction([newTr], _prevState, state)
{
const a = this.getState( state );
const b = newTr.getMeta('bodyHeight');
console.log({a, b} )
}
} );
}
Could anyone advise me how to modify it to make it work?