Automatic replacement of unnecessarily nested nodes

I am working on a custom node with two editable children(vertical split, or two columns), with the schema similar to the following.

{
  doc: {content: "container"},
  paragraph: {group: "block", content: "inline*"},
  container: {content: "block+"},
  split: {group: "block", content: "container{2}"},
}

The desired behavior is, when pressing backspace inside the empty container child of a split, the split should be replaced by the plain series of blocks. However the schema forces splits to always have two container children. I can just lift the schema restriction by letting split accept one or two children, and append a replacing transaction for every single child split, but I am wondering if there will be a better workaround for this.

Sorry if the question is not clear enough(English is not my first language), and thanks in advance.

It looks like you should be able to create a ReplaceAround step that deletes both the split’s opening/closing tokens and the empty container.

Thanks for replying! I started to love ProseMirror(although I am new to it) and I really appreciate your decision to open it to public.

One follow-up question: What is the best practice of appending the ReplaceAround step to a transaction? Where can it be handled?

If by ‘the best practice’ you mean how this is done, you’d call tr.step(new ReplaceAroundStep(...)), and make sure you get all the (rather finicky) parameter to the constructor right so that the slice and the gap produce a valid new document.

Thanks for your time, Marijn!

In case anyone reads this later, I decided to handle it in EditorView’s dispatchTransaction, which is quite trivial but wasn’t easy to figure it out as a ProseMirror novice.