on-codemerge
Version:
A WYSIWYG editor for on-codemerge is a user-friendly interface that allows users to edit and view their code in real time, exactly as it will appear in the final product
28 lines (27 loc) • 932 B
JavaScript
var e = Object.defineProperty;
var a = (r, t, s) => t in r ? e(r, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : r[t] = s;
var o = (r, t, s) => a(r, typeof t != "symbol" ? t + "" : t, s);
class u {
constructor() {
o(this, "shortcuts", []);
}
register(t, s) {
const h = t.split("+").map((c) => c.trim().toLowerCase());
this.shortcuts.push({ keys: h, callback: s });
}
handleKeyDown(t) {
const s = [];
(t.ctrlKey || t.metaKey) && s.push("ctrl"), t.shiftKey && s.push("shift"), t.altKey && s.push("alt"), t.key !== "Control" && t.key !== "Shift" && t.key !== "Alt" && s.push(t.key.toLowerCase());
for (const h of this.shortcuts)
if (this.matchesShortcut(s, h.keys)) {
t.preventDefault(), h.callback();
break;
}
}
matchesShortcut(t, s) {
return t.length !== s.length ? !1 : s.every((h) => t.includes(h));
}
}
export {
u as ShortcutManager
};