insertNewAfter method

  1. @override
ElementNode insertNewAfter({
  1. required bool isAtEnd,
})
override

Creates and inserts the element that follows this one when the user splits it — the block Enter produces.

This is the extension point for Enter behaviour, and the reason it is a virtual method rather than a switch in the command handler: a list item yields another list item, while a heading yields a paragraph, because continuing a heading is almost never what the user meant. Each of those rules belongs to the node that knows it, in its own package.

isAtEnd reports whether the caret was at the very end of this element, which is the one thing the decision usually turns on. The selection itself is deliberately not passed: a node that reaches into the selection to decide its shape is a node that behaves differently depending on how the edit arrived.

Implementation

@override
ElementNode insertNewAfter({required bool isAtEnd}) {
  // Enter always leaves the quote, even from the middle of one — that is
  // what Lexical web does, and a document edited on both must behave the
  // same way on both. To continue a quote, press Shift-Enter, which is a
  // line break rather than a block split.
  final paragraph = $createParagraphNode();
  paragraph.setDirection(getDirection());
  insertAfter(paragraph);
  return paragraph;
}