Insert a text with a link

I would like to insert a text with a link. I tried this:

const link = linkType.create({ href });
const node = state.schema.text(href).mark([link]);
dispatch(state.tr.replaceSelectionWith(node, true));

but it only inserts the text. I don’t understand what I am doing wrong.

Double-check the docs for the second argument to replaceSelectionWith.

Thank you for your answer!

I checked the doc and tried state.tr.replaceSelectionWith(node, true) and state.tr.replaceSelectionWith(node), but thought the default was false (my fault).

So, indeed, it works with state.tr.replaceSelectionWith(node, false).