How to use the roosterjs-editor-types.ContentPosition.SelectionStart function in roosterjs-editor-types

To help you get started, we’ve selected a few roosterjs-editor-types 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-dom / lib / contentTraverser / SelectionBlockScoper.ts View on Github external
public getStartInlineElement(): InlineElement {
        if (this.block) {
            switch (this.startFrom) {
                case ContentPosition.Begin:
                case ContentPosition.End:
                case ContentPosition.DomEnd:
                    return getFirstLastInlineElementFromBlockElement(
                        this.block,
                        this.startFrom == ContentPosition.Begin
                    );
                case ContentPosition.SelectionStart:
                    // Get the inline before selection start point, and ensure it falls in the selection block
                    let startInline = getInlineElementAfter(this.rootNode, this.position);
                    return startInline && this.block.contains(startInline.getContainerNode())
                        ? startInline
                        : new EmptyInlineElement(this.position, this.block);
            }
        }

        return null;
    }
github microsoft / roosterjs / packages / roosterjs-editor-plugins / lib / ContentEdit / autoBullet.ts View on Github external
function handleAutoBulletOrNumbering(identifier: string, editor: Editor) {
    let document = editor.getDocument();
    let spaceNode = document.createTextNode(' ');

    editor.insertNode(spaceNode, {
        position: ContentPosition.SelectionStart,
        updateCursor: true,
        replaceSelection: false,
        insertOnNewLine: false,
    });

    editor.addUndoSnapshot();

    editor.runWithoutAddingUndoSnapshot(() => {
        // Remove the user input '*', '-' or '1.'
        let rangeToDelete: Range = validateAndGetRangeForTextBeforeCursor(
            editor,
            identifier + ' ',
            true,
            new CursorData(editor)
        );
        if (rangeToDelete) {
github microsoft / roosterjs / packages / roosterjs-editor-core / lib / coreAPI / insertNode.ts View on Github external
insertedNode = refNode.insertBefore(node, isBegin ? refNode.firstChild : null);
                }
            } else {
                // No first block, this can happen when editor is empty. Use appendChild to insert the content in contentDiv
                insertedNode = contentDiv.appendChild(node);
            }

            // Final check to see if the inserted node is a block. If not block and the ask is to insert on new line,
            // add a DIV wrapping
            if (insertedNode && option.insertOnNewLine && !isBlockElement(insertedNode)) {
                wrap(insertedNode);
            }

            break;
        case ContentPosition.Range:
        case ContentPosition.SelectionStart:
            let { range, rangeToRestore } = getInitialRange(core, option);

            if (!range) {
                return;
            }

            // if to replace the selection and the selection is not collapsed, remove the the content at selection first
            if (option.replaceSelection && !range.collapsed) {
                range.deleteContents();
            }

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

            if (
                option.insertOnNewLine &&
github microsoft / roosterjs / packages / roosterjs-editor-plugins / lib / ContentEdit / autoBullet.ts View on Github external
// Remove the user input '*', '-' or '1.'
        let rangeToDelete: Range = validateAndGetRangeForTextBeforeCursor(
            editor,
            identifier + ' ',
            true,
            new CursorData(editor)
        );
        if (rangeToDelete) {
            rangeToDelete.deleteContents();
        }

        // If not explicitly insert br, Chrome will operate on the previous line
        if (browserData.isChrome) {
            let brNode = document.createElement('br');
            editor.insertNode(brNode, {
                position: ContentPosition.SelectionStart,
                updateCursor: true,
                replaceSelection: false,
                insertOnNewLine: false,
            });
        }

        if (identifier == '*' || identifier == '-') {
            toggleBullet(editor);
        } else if (identifier == '1.') {
            toggleNumbering(editor);
        }
    });
github microsoft / roosterjs / packages / roosterjs-editor-plugins / lib / PasteManager / PasteInterceptor.ts View on Github external
import ClipboardData from './ClipboardData';
import { Editor } from 'roosterjs-editor-core';
import { ContentPosition, InsertOption } from 'roosterjs-editor-types';
import { processImages } from './PasteUtility';

const PASTE_NODE_INSERT_OPTION: InsertOption = {
    position: ContentPosition.SelectionStart,
    updateCursor: true,
    replaceSelection: true,
    insertOnNewLine: false,
};
const InlinePositionStyle = /(<\w+[^>]*style=['"][^>]*)position:[^>;'"]*/gi;

let pasteInterceptor = function preparePasteAndPickupPostPaste(
    editor: Editor,
    clipboardData: ClipboardData,
    completeCallback: (clipboardData: ClipboardData) => void
) {
    let [originalSelectionRange, pasteContainer] = preparePasteEnvironment(editor);
    setTimeout(function() {
        onPostPaste(
            editor,
            originalSelectionRange,
github microsoft / roosterjs / publish / samplesite / scripts / controls / sidePane / apiPlayground / insertContent / InsertContentPane.tsx View on Github external
constructor(props: ApiPaneProps) {
        super(props);
        this.state = {
            content: '',
            position: ContentPosition.SelectionStart,
            updateCursor: true,
            replaceSelection: true,
            insertOnNewLine: false,
        };
    }
github microsoft / roosterjs / packages / roosterjs-editor-plugins / lib / PasteManager / PasteManager.ts View on Github external
reader.onload = (event: ProgressEvent) => {
                if (this.editor) {
                    let image = this.editor.getDocument().createElement('img');
                    image.src = (event.target as FileReader).result;
                    this.editor.insertNode(image, {
                        position: ContentPosition.SelectionStart,
                        updateCursor: true,
                        replaceSelection: true,
                        insertOnNewLine: false,
                    });
                    this.editor.addUndoSnapshot();
                }
            };
            reader.readAsDataURL(file);
github microsoft / roosterjs / packages / roosterjs-editor-core / lib / coreAPI / getContentTraverser.ts View on Github external
const getContentTraverser: GetContentTraverser = (
    core: EditorCore,
    scope: ContentScope,
    position: ContentPosition = ContentPosition.SelectionStart
) => {
    let range = core.api.getSelectionRange(core, true /*tryGetFromCache*/);

    switch (scope) {
        case ContentScope.Block:
            return (
                range &&
                ContentTraverser.createSelectionBlockTraverser(core.contentDiv, range, position)
            );
        case ContentScope.Selection:
            return range && ContentTraverser.createSelectionTraverser(core.contentDiv, range);
        case ContentScope.Body:
            return ContentTraverser.createBodyTraverser(core.contentDiv);
    }

    return null;
github microsoft / roosterjs / packages / roosterjs-editor-core / lib / coreAPI / insertNode.ts View on Github external
export const insertNode: InsertNode = (core: EditorCore, node: Node, option: InsertOption) => {
    option = option || {
        position: ContentPosition.SelectionStart,
        insertOnNewLine: false,
        updateCursor: true,
        replaceSelection: true,
    };
    let contentDiv = core.contentDiv;

    if (option.updateCursor) {
        core.api.focus(core);
    }

    switch (option.position) {
        case ContentPosition.Begin:
        case ContentPosition.End: {
            let isBegin = option.position == ContentPosition.Begin;
            let block = getFirstLastBlockElement(contentDiv, isBegin);
            let insertedNode: Node;