How to wrap an exact selection in a block node

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


But in my case, I’d like to wrap the exact selection in the quote -


How can I achieve it?

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 =;
  const node = state.schema.nodes.blockquote.create(null, state.selection.content().content);

Am I correct?

Also I implemented it using split

    if (selection.$from.parentOffset > 0) {
    if (selection.$to.parentOffset < selection.$to.node().content.size) {

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