diff --git a/packages/web/src/javascripts/Components/SuperEditor/Plugins/CollapsiblePlugin/index.ts b/packages/web/src/javascripts/Components/SuperEditor/Plugins/CollapsiblePlugin/index.ts index e71f82b91..68929ee7d 100644 --- a/packages/web/src/javascripts/Components/SuperEditor/Plugins/CollapsiblePlugin/index.ts +++ b/packages/web/src/javascripts/Components/SuperEditor/Plugins/CollapsiblePlugin/index.ts @@ -27,6 +27,7 @@ import { KEY_ARROW_LEFT_COMMAND, KEY_ARROW_RIGHT_COMMAND, KEY_ARROW_UP_COMMAND, + LexicalNode, NodeKey, } from 'lexical' import { useEffect } from 'react' @@ -83,11 +84,16 @@ export default function CollapsiblePlugin(): JSX.Element | null { if ($isCollapsibleContainerNode(container)) { const parent = container.getParent() if (parent !== null && parent.getLastChild() === container) { - const lastDescendant = container.getLastDescendant() + const titleParagraph = container.getFirstDescendant() + const contentParagraph = container.getLastDescendant() + if ( - lastDescendant !== null && - selection.anchor.key === lastDescendant.getKey() && - selection.anchor.offset === lastDescendant.getTextContentSize() + (contentParagraph !== null && + selection.anchor.key === contentParagraph.getKey() && + selection.anchor.offset === contentParagraph.getTextContentSize()) || + (titleParagraph !== null && + selection.anchor.key === titleParagraph.getKey() && + selection.anchor.offset === titleParagraph.getTextContentSize()) ) { container.insertAfter($createParagraphNode()) }