How to use the roosterjs-editor-dom.contains 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 / coreAPI / createEventHandlers.ts View on Github external
function selectEditorPoint(core: EditorCore, container: Node, offset: number): boolean {
    if (!container || !contains(core.contentDiv, container)) {
        return false;
    }

    let range = core.document.createRange();
    if (container.nodeType == NodeType.Text && offset <= container.nodeValue.length) {
        range.setStart(container, offset);
    } else if (offset == NodeBoundary.Begin) {
        range.setStartBefore(container);
    } else {
        range.setStartAfter(container);
    }

    range.collapse(true /* toStart */);

    return updateSelection(core, range);
}
github microsoft / roosterjs / packages / roosterjs-editor-core / lib / coreAPI / selectRange.ts View on Github external
export const selectRange: SelectRange = (
    core: EditorCore,
    range: Range,
    skipSameRange?: boolean
) => {
    let selection: Selection;
    let needAddRange = true;

    if (
        !contains(core.contentDiv, range) ||
        !(selection = core.document.defaultView.getSelection())
    ) {
        return false;
    }

    if (selection.rangeCount > 0) {
        // Workaround IE exception 800a025e
        try {
            let currentRange: Range;
            // Do not remove/add range if current selection is the same with target range
            // Without this check, execCommand() may fail in Edge since we changed the selection
            if (
                (skipSameRange || Browser.isEdge) &&
                (currentRange = selection.rangeCount == 1 ? selection.getRangeAt(0) : null) &&
                currentRange.startContainer == range.startContainer &&
                currentRange.startOffset == range.startOffset &&
github microsoft / roosterjs / packages / roosterjs-editor-core / lib / coreAPI / selection.ts View on Github external
export function hasFocus(core: EditorCore): boolean {
    let activeElement = core.document.activeElement;
    return (
        activeElement &&
        (core.contentDiv == activeElement || contains(core.contentDiv, activeElement))
    );
}
github microsoft / roosterjs / packages / roosterjs-editor-plugins / lib / ContentEdit / features / tableFeatures.ts View on Github external
editor.runAsync(() => {
            let newContainer = editor.getElementAtCursor();
            if (
                contains(vtable.table, newContainer) &&
                !contains(td, newContainer, true /*treatSameNodeAsContain*/)
            ) {
                let newPos = targetTd
                    ? new Position(targetTd, PositionType.Begin)
                    : new Position(vtable.table, isUp ? PositionType.Before : PositionType.After);
                if (hasShiftKey) {
                    newPos =
                        newPos.node.nodeType == NodeType.Element && isVoidHtmlElement(newPos.node)
                            ? new Position(
                                  newPos.node,
                                  newPos.isAtEnd ? PositionType.After : PositionType.Before
                              )
                            : newPos;
                    editor
                        .getSelection()
                        .setBaseAndExtent(anchorNode, anchorOffset, newPos.node, newPos.offset);
                } else {
github microsoft / roosterjs / packages / roosterjs-editor-core / lib / editor / Editor.ts View on Github external
public contains(node: Node): boolean {
        return contains(this.core.contentDiv, node);
    }
github microsoft / roosterjs / packages / roosterjs-editor-plugins / lib / ContentEdit / features / tableFeatures.ts View on Github external
editor.runAsync(() => {
            let newContainer = editor.getElementAtCursor();
            if (
                contains(vtable.table, newContainer) &&
                !contains(td, newContainer, true /*treatSameNodeAsContain*/)
            ) {
                let newPos = targetTd
                    ? new Position(targetTd, PositionType.Begin)
                    : new Position(vtable.table, isUp ? PositionType.Before : PositionType.After);
                if (hasShiftKey) {
                    newPos =
                        newPos.node.nodeType == NodeType.Element && isVoidHtmlElement(newPos.node)
                            ? new Position(
                                  newPos.node,
                                  newPos.isAtEnd ? PositionType.After : PositionType.Before
                              )
                            : newPos;
                    editor
                        .getSelection()
                        .setBaseAndExtent(anchorNode, anchorOffset, newPos.node, newPos.offset);