Multiple toggle marks in one transaction

Hii, I’m pretty new to Prosemirror. I want to update the marks applied to a selection. The approach I have undertaken is toggling it back to the previous state(with toggleMark) and then toggling it to the new state with the updated marks.

toggleMark(schema.marks.colorPicker)(state, dispatch);
toggleMark(schema.marks.colorPicker, { fontColor })(state,dispatch,);

But it’s throwing this error [RangeError: Applying a mismatched transaction] which I assume due to the state in the function body being stale. I think I am looking for the solution to multiple toggleMark() dispatches in one go. If anything strikes as erroneous or you have any suggestions please let me know.

Thank you!

Hi @aritra

Welcome to ProseMirror :slight_smile:

I think you’re right on the money there. The second time you are calling toggleMark with an outdated state. Without digging deeper I would say that calling the command with (view.state, dispatch) instead of the outdated state will probably fix your issue.

If not, it might help to understand in what context you are executing these commands.

Kindly

Frederik

1 Like

Thanks a lot @frederik! It worked like a charm :grin: