From e9c9d9f4dbcda646bb400db373d8cdeda7e1e3f1 Mon Sep 17 00:00:00 2001 From: eagowang <15527179911@163.com> Date: Fri, 20 Jan 2023 20:54:43 +0800 Subject: [PATCH] Fix forced-layout example trigger insert untitle node (#5263) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 锐雯 --- site/examples/forced-layout.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/site/examples/forced-layout.tsx b/site/examples/forced-layout.tsx index 2ec9bb135..116b358ae 100644 --- a/site/examples/forced-layout.tsx +++ b/site/examples/forced-layout.tsx @@ -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) {