Hello! I am trying to implement a quote node type as in the main example, but you can see that if we select just the part of the text, for example,
“456” from <p>123456</p>
and use the wrapIn command, the range will be expanded to the whole node “123456” and the quote node type will be applied to the whole block
<blockquote><p>123456</p></blockquote>.
But in my case, I’d like to wrap the exact selection in the quote -
<p>123</p><blockquote><p>456</p></blockquote>.
How can I achieve it?
marijn
2
You’d have to write a custom command that first splits off the selected text. wrapIn
works on whole block nodes.
I decided to implement in this way
const tr = state.tr;
const node = state.schema.nodes.blockquote.create(null, state.selection.content().content);
tr.replaceSelectionWith(node).scrollIntoView();
dispatch(tr);
Am I correct?
Also I implemented it using split
if (selection.$from.parentOffset > 0) {
tr.split(tr.mapping.map(selection.from));
}
if (selection.$to.parentOffset < selection.$to.node().content.size) {
tr.split(tr.mapping.map(selection.to));
}
and then
wrapIn(nodeType)(view.state, dispatch, view);
but unfortunately wrapIn some how wraps the selection node as expected and also the node after selection but I do not need it