mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-20 22:21:20 +02:00
Fix forced-layout example trigger insert untitle node (#5263)
Co-authored-by: 锐雯 <wangyichen@xiaohongshu.com>
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
||||
Node,
|
||||
Element as SlateElement,
|
||||
Descendant,
|
||||
Editor,
|
||||
} from 'slate'
|
||||
import { withHistory } from 'slate-history'
|
||||
import { ParagraphElement, TitleElement } from './custom-types'
|
||||
@@ -15,12 +16,15 @@ const withLayout = editor => {
|
||||
|
||||
editor.normalizeNode = ([node, path]) => {
|
||||
if (path.length === 0) {
|
||||
if (editor.children.length < 1) {
|
||||
if (editor.children.length <= 1 && Editor.string(editor, [0, 0]) === '') {
|
||||
const title: TitleElement = {
|
||||
type: 'title',
|
||||
children: [{ text: 'Untitled' }],
|
||||
}
|
||||
Transforms.insertNodes(editor, title, { at: path.concat(0) })
|
||||
Transforms.insertNodes(editor, title, {
|
||||
at: path.concat(0),
|
||||
select: true,
|
||||
})
|
||||
}
|
||||
|
||||
if (editor.children.length < 2) {
|
||||
|
Reference in New Issue
Block a user