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,
|
Node,
|
||||||
Element as SlateElement,
|
Element as SlateElement,
|
||||||
Descendant,
|
Descendant,
|
||||||
|
Editor,
|
||||||
} from 'slate'
|
} from 'slate'
|
||||||
import { withHistory } from 'slate-history'
|
import { withHistory } from 'slate-history'
|
||||||
import { ParagraphElement, TitleElement } from './custom-types'
|
import { ParagraphElement, TitleElement } from './custom-types'
|
||||||
@@ -15,12 +16,15 @@ const withLayout = editor => {
|
|||||||
|
|
||||||
editor.normalizeNode = ([node, path]) => {
|
editor.normalizeNode = ([node, path]) => {
|
||||||
if (path.length === 0) {
|
if (path.length === 0) {
|
||||||
if (editor.children.length < 1) {
|
if (editor.children.length <= 1 && Editor.string(editor, [0, 0]) === '') {
|
||||||
const title: TitleElement = {
|
const title: TitleElement = {
|
||||||
type: 'title',
|
type: 'title',
|
||||||
children: [{ text: 'Untitled' }],
|
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) {
|
if (editor.children.length < 2) {
|
||||||
|
Reference in New Issue
Block a user