How to use the roosterjs-editor-api.setBackgroundColor function in roosterjs-editor-api

To help you get started, we’ve selected a few roosterjs-editor-api 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-react / packages / roosterjs-react-command-bar / lib / utils / OutOfBoxCommandBarButtons.tsx View on Github external
function _handleChangeForHighlight(editor: Editor): void {
    const { color } = this.data as ColorInfo;
    const selection = editor.getSelection();
    let backwards = false;
    if (!selection.isCollapsed) {
        const range = editor.getDocument().createRange();
        range.setStart(selection.anchorNode, selection.anchorOffset);
        range.setEnd(selection.focusNode, selection.focusOffset);
        backwards = range.collapsed;
    }

    setBackgroundColor(editor, color);
    if (backwards) {
        selection.collapseToStart();
    } else {
        selection.collapseToEnd();
    }
}
github microsoft / roosterjs / sample / scripts / initFormatBar.ts View on Github external
document.getElementById('backColorButton').addEventListener('change', function() {
        let editor = getCurrentEditor();
        let select = document.getElementById('backColorButton') as HTMLSelectElement;
        let text = select.value;
        if (text) {
            setBackgroundColor(editor, text);
        }
        select.value = '';
    });
}