import { CommonSliceType } from '../../../json-crdt-extensions/peritext';
export class RichTextController {
    dom;
    constructor(dom) {
        this.dom = dom;
    }
    /** -------------------------------------------------- {@link UiLifeCycles} */
    start() {
        const dom = this.dom;
        const el = dom.el;
        const onKeyDown = (event) => {
            const key = event.key;
            if (event.isComposing || key === 'Dead')
                return;
            const et = dom.et;
            if (event.metaKey || event.ctrlKey) {
                switch (key) {
                    case 'b':
                        event.preventDefault();
                        et.format('tog', CommonSliceType.b);
                        return;
                    case 'i':
                        event.preventDefault();
                        et.format('tog', CommonSliceType.i);
                        return;
                    case 'u':
                        event.preventDefault();
                        et.format('tog', CommonSliceType.u);
                        return;
                }
            }
            if (event.metaKey && event.shiftKey) {
                switch (key) {
                    case 'x':
                        event.preventDefault();
                        et.format('tog', CommonSliceType.s);
                        return;
                }
            }
        };
        el.addEventListener('keydown', onKeyDown);
        return () => {
            el.removeEventListener('keydown', onKeyDown);
        };
    }
}
//# sourceMappingURL=RichTextController.js.map