From 0ab9006c52569f97e185210e45ef7eafb1fb13c6 Mon Sep 17 00:00:00 2001 From: Aman Harwara Date: Fri, 28 Apr 2023 16:26:02 +0530 Subject: [PATCH] chore: update collapsible plugin --- .../Plugins/CollapsiblePlugin/index.ts | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) 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 f2025bba4..03ca3a3bb 100644 --- a/packages/web/src/javascripts/Components/SuperEditor/Plugins/CollapsiblePlugin/index.ts +++ b/packages/web/src/javascripts/Components/SuperEditor/Plugins/CollapsiblePlugin/index.ts @@ -9,7 +9,7 @@ import './Collapsible.css' import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext' -import { $findMatchingParent, mergeRegister } from '@lexical/utils' +import { $findMatchingParent, mergeRegister, $insertNodeToNearestRoot } from '@lexical/utils' import { $createParagraphNode, $getNodeByKey, @@ -202,17 +202,14 @@ export default function CollapsiblePlugin(): JSX.Element | null { INSERT_COLLAPSIBLE_COMMAND, () => { editor.update(() => { - const selection = $getSelection() - - if (!$isRangeSelection(selection)) { - return - } - const title = $createCollapsibleTitleNode() - const content = $createCollapsibleContentNode().append($createParagraphNode()) - const container = $createCollapsibleContainerNode(true).append(title, content) - selection.insertNodes([container]) - title.selectStart() + $insertNodeToNearestRoot( + $createCollapsibleContainerNode(true).append( + title, + $createCollapsibleContentNode().append($createParagraphNode()), + ), + ) + title.select() }) return true