How to use the roosterjs-editor-dom.isNodeEmpty function in roosterjs-editor-dom

To help you get started, we’ve selected a few roosterjs-editor-dom examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github microsoft / roosterjs / packages / roosterjs-editor-core / lib / corePlugins / TypeInContainerPlugin.ts View on Github external
ensureTypeInElement(position: NodePosition, event?: PluginKeyboardEvent): NodePosition {
        let result = position.normalize();
        let block = this.editor.getBlockElementAtNode(result.node);
        let formatNode: HTMLElement;

        if (block) {
            formatNode = block.collapseToSingleElement();

            // if the block is empty, apply default format
            // Otherwise, leave it as it is as we don't want to change the style for existing data
            // unless the block was just created by the keyboard event (e.g. ctrl+a & start typing)
            const shouldSetNodeStyles =
                isNodeEmpty(formatNode) ||
                (event && this.wasNodeJustCreatedByKeyboardEvent(event, formatNode));
            formatNode = formatNode && shouldSetNodeStyles ? formatNode : null;
        } else {
            // Only reason we don't get the selection block is that we have an empty content div
            // which can happen when users removes everything (i.e. select all and DEL, or backspace from very end to begin)
            // The fix is to add a DIV wrapping, apply default format and move cursor over
            formatNode = fromHtml(
                Browser.isEdge ? '<div><span><br></span></div>' : '<div><br></div>',
                this.editor.getDocument()
            )[0] as HTMLElement;
            this.editor.insertNode(formatNode, {
                position: ContentPosition.End,
                updateCursor: false,
                replaceSelection: false,
                insertOnNewLine: false,
            });
github microsoft / roosterjs / packages / roosterjs-editor-plugins / lib / ContentEdit / features / listFeatures.ts View on Github external
shouldHandleEvent: (event, editor) => {
        let li = cacheGetElementAtCursor(editor, event, 'LI');
        return li && isNodeEmpty(li) && !li.previousSibling;
    },
    handleEvent: toggleListAndPreventDefault,
github microsoft / roosterjs / packages / roosterjs-editor-plugins / lib / ContentEdit / features / quoteFeatures.ts View on Github external
return cacheGetEventData(event, 'QUOTE_CHILD', () => {
        let quote = editor.getElementAtCursor(STRUCTURED_TAGS);
        if (quote && getTagOfNode(quote) == QUOTE_TAG) {
            let pos = editor.getFocusedPosition();
            let block = pos && editor.getBlockElementAtNode(pos.normalize().node);
            if (block) {
                let node =
                    block.getStartNode() == quote
                        ? block.getStartNode()
                        : block.collapseToSingleElement();
                return isNodeEmpty(node) ? node : null;
            }
        }

        return null;
    });
}
github microsoft / roosterjs / packages / roosterjs-editor-plugins / lib / ContentEdit / features / quoteFeatures.ts View on Github external
shouldHandleEvent: (event, editor) => {
        let childOfQuote = cacheGetQuoteChild(event, editor);
        let shift = event.rawEvent.shiftKey;
        return !shift && childOfQuote && isNodeEmpty(childOfQuote);
    },
    handleEvent: (event, editor) => editor.performAutoComplete(() => splitQuote(event, editor)),
github microsoft / roosterjs / packages / roosterjs-editor-plugins / lib / ContentEdit / features / quoteFeatures.ts View on Github external
shouldHandleEvent: (event, editor) => {
        let childOfQuote = cacheGetQuoteChild(event, editor);
        return childOfQuote && isNodeEmpty(childOfQuote) && !childOfQuote.previousSibling;
    },
    handleEvent: splitQuote,
github microsoft / roosterjs / packages / roosterjs-editor-core / lib / editor / Editor.ts View on Github external
public isEmpty(trim?: boolean): boolean {
        return isNodeEmpty(this.core.contentDiv, trim);
    }