"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RichTextController = void 0;
const peritext_1 = require("../../../json-crdt-extensions/peritext");
class RichTextController {
    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', peritext_1.CommonSliceType.b);
                        return;
                    case 'i':
                        event.preventDefault();
                        et.format('tog', peritext_1.CommonSliceType.i);
                        return;
                    case 'u':
                        event.preventDefault();
                        et.format('tog', peritext_1.CommonSliceType.u);
                        return;
                }
            }
            if (event.metaKey && event.shiftKey) {
                switch (key) {
                    case 'x':
                        event.preventDefault();
                        et.format('tog', peritext_1.CommonSliceType.s);
                        return;
                }
            }
        };
        el.addEventListener('keydown', onKeyDown);
        return () => {
            el.removeEventListener('keydown', onKeyDown);
        };
    }
}
exports.RichTextController = RichTextController;
//# sourceMappingURL=RichTextController.js.map