Issue with node creation on Enter

Hi,

I have a nodeSpec doc_header with the following content:

title author? revision?

where title, author, and revision are all inline text nodes.

After creating such a node, when I hit Enter at the end of the title, I expect an author node to be created, but instead it creates a revision node.

Any idea why? (My app is based on the basic example-setup module. It is using the default bindings for Enter).

Thanks, michel

Does revision appear before author in your schema definition?

No. Here the part of the schema:

function inlineNodeSpec(className: string): NodeSpec {
  return {
    content: 'inline*',
    parseDOM: [{ tag: 'div', attrs: {class: className} }],
    toDOM() { return ['div', {class: className}, 0]}
  }
}

export const nodes: {[name in NodeNames]: NodeSpec} = {
  doc: {
    content: 'doc_header? (block_title? block)*'
  },

  doc_header: {
    content: 'doc_title authors? revision?',
    parseDOM: [{ tag: 'div', attrs: {class: 'doc_header'} }],
    toDOM() { return ['div', {class: 'doc_header'}, 0]}
  },

  doc_title: inlineNodeSpec('doc_title'),
  authors: inlineNodeSpec('authors'),
  revision: inlineNodeSpec('revision'),
  ...

Oh right, I see. There’s not really any guarantee on which node is going to be picked in a situation like this. Your best bet would be to bind a custom command to Enter with a higher precedence than the default commands used for enter, and in that command function, check whether the cursor is in a doc_header, and if it is, implement the intended behavior (possibly using splitBlockAs as a primitive).