Skip to content

slate-yjs demo withNormalize plugin Constant insertion of ‘’ characters problem #424

@ZhangMingZhao1

Description

@ZhangMingZhao1
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions