Open ZhangMingZhao1 opened 5 months ago
import { Editor, Transforms } from 'slate'; export function withNormalize(editor: Editor) { const { normalizeNode } = editor; // Ensure editor always has at least one child. editor.normalizeNode = (entry) => { const [node] = entry; console.log('node.children', node.children); if (!Editor.isEditor(node) || node.children.length > 0) { return normalizeNode(entry); // return; } // if() Transforms.insertNodes( editor, { type: 'paragraph', children: [{ text: '' }] }, { at: [0] } ); }; return editor; }
this project demo use withNormalize plugin,because normalizeNode can execute multiple times, (!Editor.isEditor(node) || node.children.length > 0) 。This code snippet is likely to be executed every time the document is initialized
this project demo use withNormalize plugin,because normalizeNode can execute multiple times, (!Editor.isEditor(node) || node.children.length > 0) 。This code snippet is likely to be executed every time the document is initialized