Nested sections and splitBlock

Hi,

I’m trying to design a schema with an explicit section node:

  section: {
    content: "title block* section*",
    parseDOM: [{tag: "section"}],
    toDOM() { return ["section", 0] }
  },
  title: {
    content: "inline*",
    defining: true,
    parseDOM: [{tag: "h1"}],
    toDOM(node) { return ["h1", 0] }
  },

As you can see, these sections can be nested.

I run into an issue with the behaviour of “Enter” at the end of the section title; nothing happens, no new default block item (paragraph) is inserted after the title.

Debugging the issue, I see that ProseMirror wants to insert a section node instead of a paragraph. I’m not sure why it doesn’t succeed, but I don’t want that anyway (new sections should only be created when the user clicks the menu button). How can I make splitBlock add a paragraph instead?

Or do I need to supply a custom command to properly handle “Enter” in sections myself?

The document node has the same issue:

  doc: {
    content: "(block | section)+ section*"
  },

Thanks

I think the problem is the order in which you are declaring your nodes in the schema. This is significant, in that it determines which node type is created by default. If you make sure that your paragraph type is above all other block-level node types, that might help.

Hi Marijn,

I don’t think that is the issue. That requirement did confuse me earlier, though.

Paragraph (with group: “block”) is the third node in my schema, after ‘doc’ and ‘text’. Also note that section is not part of the ‘block’ group.

Oh, this may actually be introduced in prosemirror-model 1.7.4. Because of a fix of another issue, it will now, for the sub-expression block* section*, default to trying to add the latter.

The defaultType getter is a bit underdefined, I guess—there’s no obvious right answer for a case like this. Maybe splitBlock should do the search itself, but that’s also awkward.

Downgrading to 1.7.3 fixes the issue, indeed! What do you suggest going forward? Do you intend on reverting the behavior introduced in 1.7.4, or should I write a custom ‘Enter’ handling command to handle my sections?

I could have a go at writing a prosemirror-model patch myself, but I’m new to ProseMirror development and Javascript development in general, so I’m a bit hesitant.

In any case, thanks for a wonderful editor!

I don’t have time to dig into this today, but I’ll take a look soon. I think having a custom enter command that kicks in in headings is probably the easiest quick solution, for now.

I’ve run into the exact same problem, it works perfectly as expected in prosemirror-model 1.7.3 and doesn’t after 1.7.4. I’d rather spend time working on a fix for everybody than a custom command just for me so tell me if I can help here.