A question about the automatic joining of paragraphs

Hallo!

I have a question about the automatic joining of paragraphs when deleting text. The schema I use is something like the following:

paragraph: {
  content: 'inline*',
  group: 'block',
  // ...
},
customBlock: {
  content: 'block+',
  group: 'block',
  // ...
  toDOM: function toDOM(node) {
    return ['div', node.attrs, 0]
  },
},

The schema allows for free paragraphs as well as paragraphs nested inside the customBlock.

While playing around with the editor I noticed the following behavior: if I have a free paragraph followed by a customBlock with a single nested paragraph and I select text from both the first and the nested paragraphs and hit the delete button then the remaining text of the first paragraph is joined with the remaining text of the nested paragraph and the customBlock is completely removed in the process. So let’s say that [ and ] brackets mark the beginning and the end of a selection.

<p>one [two</p>
<div>
  <p>three ]four</p>
</div>

“Delete” ->

<p>one four</p>

My question is: is there a way to keep the customBlock from being removed? Is it possible when hitting “Delete” to get this structure instead?

<p>one </p>
<div>
  <p>four</p>
</div>

I tried setting defining: true and isolating: true to the customBlock node in the schema but it did not changed the behavior of the node so I guess they are used for different scenarios.

Best regards,

Ivan

Not with the built-in delete commands, but if you want you can bind custom commands to the various deletion-related keys that kick in in cases like this.

I guess I should bind not only deletion-related keys but also most of the other keys. Pressing “a” in the described scenario will give something like this:

<p>one afour</p>

That is it will delete the customBlock and insert “a” at the anchor of the selection. Is there a way I can plug in the process of deletion? I read the code of tr.deleteSelection() looking for some kind of a hook provided by node types but could not find any.

Nope, there’s no way to override every type of deletion at the moment.

I understand. Thank you for your time!

Best regards,

Ivan