Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ZhangMingZhao1 opened this issue Jun 26, 2024 · 0 comments

Comments

@ZhangMingZhao1
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant