How to use the roosterjs-editor-dom.createRange 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 / insertNode.ts View on Github external
}

            let pos = Position.getStart(range);
            let blockElement: BlockElement;

            if (
                option.insertOnNewLine &&
                (blockElement = getBlockElementAtNode(contentDiv, pos.normalize().node))
            ) {
                pos = new Position(blockElement.getEndNode(), PositionType.After);
            } else {
                pos = adjustNodeInsertPosition(contentDiv, node, pos);
            }

            let nodeForCursor = node.nodeType == NodeType.DocumentFragment ? node.lastChild : node;
            range = createRange(pos);
            range.insertNode(node);
            if (option.updateCursor && nodeForCursor) {
                rangeToRestore = createRange(
                    new Position(nodeForCursor, PositionType.After).normalize()
                );
            }
            core.api.selectRange(core, rangeToRestore);

            break;
        case ContentPosition.Outside:
            core.contentDiv.parentNode.insertBefore(node, contentDiv.nextSibling);
            break;
    }

    return true;
};
github microsoft / roosterjs / packages / roosterjs-editor-core / lib / coreAPI / insertNode.ts View on Github external
let blockElement: BlockElement;

            if (
                option.insertOnNewLine &&
                (blockElement = getBlockElementAtNode(contentDiv, pos.normalize().node))
            ) {
                pos = new Position(blockElement.getEndNode(), PositionType.After);
            } else {
                pos = adjustNodeInsertPosition(contentDiv, node, pos);
            }

            let nodeForCursor = node.nodeType == NodeType.DocumentFragment ? node.lastChild : node;
            range = createRange(pos);
            range.insertNode(node);
            if (option.updateCursor && nodeForCursor) {
                rangeToRestore = createRange(
                    new Position(nodeForCursor, PositionType.After).normalize()
                );
            }
            core.api.selectRange(core, rangeToRestore);

            break;
        case ContentPosition.Outside:
            core.contentDiv.parentNode.insertBefore(node, contentDiv.nextSibling);
            break;
    }

    return true;
};
github microsoft / roosterjs / packages / roosterjs-editor-core / lib / coreAPI / insertNode.ts View on Github external
}

            let pos = Position.getStart(range);
            let blockElement: BlockElement;

            if (
                option.insertOnNewLine &&
                (blockElement = getBlockElementAtNode(contentDiv, pos.normalize().node))
            ) {
                pos = new Position(blockElement.getEndNode(), PositionType.After);
            } else {
                pos = adjustNodeInsertPosition(contentDiv, node, pos);
            }

            let nodeForCursor = node.nodeType == NodeType.DocumentFragment ? node.lastChild : node;
            range = createRange(pos);
            range.insertNode(node);
            if (option.updateCursor && nodeForCursor) {
                rangeToRestore = createRange(
                    new Position(nodeForCursor, PositionType.After).normalize()
                );
            }
            core.api.selectRange(core, rangeToRestore);

            break;
        case ContentPosition.Outside:
            core.contentDiv.parentNode.insertBefore(node, contentDiv.nextSibling);
            break;
    }

    return true;
};
github microsoft / roosterjs / packages / roosterjs-editor-core / lib / coreAPI / insertNode.ts View on Github external
let blockElement: BlockElement;

            if (
                option.insertOnNewLine &&
                (blockElement = getBlockElementAtNode(contentDiv, pos.normalize().node))
            ) {
                pos = new Position(blockElement.getEndNode(), PositionType.After);
            } else {
                pos = adjustNodeInsertPosition(contentDiv, node, pos);
            }

            let nodeForCursor = node.nodeType == NodeType.DocumentFragment ? node.lastChild : node;
            range = createRange(pos);
            range.insertNode(node);
            if (option.updateCursor && nodeForCursor) {
                rangeToRestore = createRange(
                    new Position(nodeForCursor, PositionType.After).normalize()
                );
            }
            core.api.selectRange(core, rangeToRestore);

            break;
        case ContentPosition.Outside:
            core.contentDiv.parentNode.insertBefore(node, contentDiv.nextSibling);
            break;
    }

    return true;
};
github microsoft / roosterjs / packages / roosterjs-plugin-picker / lib / PickerPlugin.ts View on Github external
while (nodeIndex >= 0) {
                if (nodeContent[nodeIndex] == this.pickerOptions.triggerCharacter) {
                    startPos = textInline.getStartPosition().move(nodeIndex);
                    hasMatched = true;
                    break;
                }
                nodeIndex--;
            }

            if (hasMatched) {
                endPos = textInline.getEndPosition();
            }

            return hasMatched;
        });
        return createRange(startPos, endPos) || this.editor.getDocument().createRange();
    }
github microsoft / roosterjs / publish / samplesite / scripts / controls / sidePane / apiPlayground / blockElements / BlockElementsPane.tsx View on Github external
function getTextContent(block: BlockElement): string {
    return block.getStartNode() == block.getEndNode()
        ? block.getStartNode().textContent
        : createRange(block.getStartNode(), block.getEndNode()).toString();
}
github microsoft / roosterjs / packages / roosterjs-editor-core / lib / coreAPI / selectRange.ts View on Github external
export const select: Select = (core: EditorCore, arg1: any, arg2?: any, arg3?: any, arg4?: any) => {
    let range = arg1 instanceof Range ? arg1 : createRange(arg1, arg2, arg3, arg4);
    return core.api.selectRange(core, range);
};