chore: update collapsible plugin
This commit is contained in:
@@ -9,7 +9,7 @@
|
|||||||
import './Collapsible.css'
|
import './Collapsible.css'
|
||||||
|
|
||||||
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'
|
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'
|
||||||
import { $findMatchingParent, mergeRegister } from '@lexical/utils'
|
import { $findMatchingParent, mergeRegister, $insertNodeToNearestRoot } from '@lexical/utils'
|
||||||
import {
|
import {
|
||||||
$createParagraphNode,
|
$createParagraphNode,
|
||||||
$getNodeByKey,
|
$getNodeByKey,
|
||||||
@@ -202,17 +202,14 @@ export default function CollapsiblePlugin(): JSX.Element | null {
|
|||||||
INSERT_COLLAPSIBLE_COMMAND,
|
INSERT_COLLAPSIBLE_COMMAND,
|
||||||
() => {
|
() => {
|
||||||
editor.update(() => {
|
editor.update(() => {
|
||||||
const selection = $getSelection()
|
|
||||||
|
|
||||||
if (!$isRangeSelection(selection)) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const title = $createCollapsibleTitleNode()
|
const title = $createCollapsibleTitleNode()
|
||||||
const content = $createCollapsibleContentNode().append($createParagraphNode())
|
$insertNodeToNearestRoot(
|
||||||
const container = $createCollapsibleContainerNode(true).append(title, content)
|
$createCollapsibleContainerNode(true).append(
|
||||||
selection.insertNodes([container])
|
title,
|
||||||
title.selectStart()
|
$createCollapsibleContentNode().append($createParagraphNode()),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
title.select()
|
||||||
})
|
})
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|||||||
Reference in New Issue
Block a user