-
-
Notifications
You must be signed in to change notification settings - Fork 77
Open
Description
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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels