How to use the roosterjs-editor-core.Keys.CONTENTCHANGED function in roosterjs-editor-core

To help you get started, we’ve selected a few roosterjs-editor-core 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-plugins / lib / ContentEdit / features / listFeatures.ts View on Github external
export function getSmartOrderedList(
    styleList: string[]
): GenericContentEditFeature {
    return {
        keys: [Keys.CONTENTCHANGED], // Triggered by ContentChangedEvent
        shouldHandleEvent: (event, editor) => event.data instanceof HTMLOListElement,
        handleEvent: (event, editor) => {
            let ol = event.data as HTMLOListElement;
            let parentOl = editor.getElementAtCursor('OL', ol.parentNode) as HTMLOListElement;
            if (parentOl) {
                // The style list must has at least one value. If no value is passed in, fallback to decimal
                let styles = styleList && styleList.length > 0 ? styleList : ['decimal'];
                ol.style.listStyle =
                    styles[(styles.indexOf(parentOl.style.listStyle) + 1) % styles.length];
            }
        },
    };
}