Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(editor): keep empty paragraph when inserting a block node into an empty doc (#5087)

Eric Hayesa2ba2113babb
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/utils.ts b/apps/web/src/lib/core/component/LexicalMarkdown/utils.ts
index 7caf45ff80..82dd8d9a3e 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/utils.ts
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/utils.ts
@@ -1069,6 +1069,21 @@ export function $insertNodesAndSplitList(nodes: LexicalNode[]) {
}
const matchingParent = $findMatchingParent(node, $isListItemNode);
if (!matchingParent) {
+ const topLevelElement = node.getTopLevelElement();
+ if (
+ anchor.offset === 0 &&
+ topLevelElement &&
+ topLevelElement.isEmpty() &&
+ topLevelElement === $getRoot().getFirstChild() &&
+ topLevelElement === $getRoot().getLastChild()
+ ) {
+ // Inserting via $insertNodes here would delete this lone empty
+ // block once the new (non-mergeable, e.g. decorator) nodes are
+ // placed after it, leaving no element for the cursor to land in.
+ // Insert before it instead so it survives as a place to type.
+ $getRoot().splice(0, 0, nodes);
+ return;
+ }
$insertNodes(nodes);
nodes.at(-1)?.selectEnd();
return;