2020-12-12 23:03:58 +01:00
|
|
|
import { t } from "../i18n";
|
|
|
|
import { isDarwin } from "../keys";
|
|
|
|
import { getShortcutKey } from "../utils";
|
|
|
|
|
|
|
|
export type ShortcutName =
|
|
|
|
| "cut"
|
|
|
|
| "copy"
|
|
|
|
| "paste"
|
|
|
|
| "copyStyles"
|
|
|
|
| "pasteStyles"
|
|
|
|
| "selectAll"
|
2021-01-28 00:41:17 +05:30
|
|
|
| "deleteSelectedElements"
|
2020-12-12 23:03:58 +01:00
|
|
|
| "duplicateSelection"
|
|
|
|
| "sendBackward"
|
|
|
|
| "bringForward"
|
|
|
|
| "sendToBack"
|
|
|
|
| "bringToFront"
|
|
|
|
| "copyAsPng"
|
|
|
|
| "copyAsSvg"
|
|
|
|
| "group"
|
|
|
|
| "ungroup"
|
2020-12-20 23:20:03 +01:00
|
|
|
| "gridMode"
|
2021-01-06 11:23:05 -05:00
|
|
|
| "zenMode"
|
2020-12-20 23:20:03 +01:00
|
|
|
| "stats"
|
2020-12-12 23:03:58 +01:00
|
|
|
| "addToLibrary";
|
|
|
|
|
|
|
|
const shortcutMap: Record<ShortcutName, string[]> = {
|
|
|
|
cut: [getShortcutKey("CtrlOrCmd+X")],
|
|
|
|
copy: [getShortcutKey("CtrlOrCmd+C")],
|
|
|
|
paste: [getShortcutKey("CtrlOrCmd+V")],
|
|
|
|
copyStyles: [getShortcutKey("CtrlOrCmd+Alt+C")],
|
|
|
|
pasteStyles: [getShortcutKey("CtrlOrCmd+Alt+V")],
|
|
|
|
selectAll: [getShortcutKey("CtrlOrCmd+A")],
|
2021-01-28 00:41:17 +05:30
|
|
|
deleteSelectedElements: [getShortcutKey("Del")],
|
2020-12-12 23:03:58 +01:00
|
|
|
duplicateSelection: [
|
|
|
|
getShortcutKey("CtrlOrCmd+D"),
|
2021-01-17 17:46:23 +01:00
|
|
|
getShortcutKey(`Alt+${t("helpDialog.drag")}`),
|
2020-12-12 23:03:58 +01:00
|
|
|
],
|
|
|
|
sendBackward: [getShortcutKey("CtrlOrCmd+[")],
|
|
|
|
bringForward: [getShortcutKey("CtrlOrCmd+]")],
|
|
|
|
sendToBack: [
|
|
|
|
isDarwin
|
|
|
|
? getShortcutKey("CtrlOrCmd+Alt+[")
|
|
|
|
: getShortcutKey("CtrlOrCmd+Shift+["),
|
|
|
|
],
|
|
|
|
bringToFront: [
|
|
|
|
isDarwin
|
|
|
|
? getShortcutKey("CtrlOrCmd+Alt+]")
|
|
|
|
: getShortcutKey("CtrlOrCmd+Shift+]"),
|
|
|
|
],
|
|
|
|
copyAsPng: [getShortcutKey("Shift+Alt+C")],
|
|
|
|
copyAsSvg: [],
|
|
|
|
group: [getShortcutKey("CtrlOrCmd+G")],
|
|
|
|
ungroup: [getShortcutKey("CtrlOrCmd+Shift+G")],
|
2020-12-20 23:20:03 +01:00
|
|
|
gridMode: [getShortcutKey("CtrlOrCmd+'")],
|
2021-01-06 11:23:05 -05:00
|
|
|
zenMode: [getShortcutKey("Alt+Z")],
|
2020-12-20 23:20:03 +01:00
|
|
|
stats: [],
|
2020-12-12 23:03:58 +01:00
|
|
|
addToLibrary: [],
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getShortcutFromShortcutName = (name: ShortcutName) => {
|
|
|
|
const shortcuts = shortcutMap[name];
|
|
|
|
// if multiple shortcuts availiable, take the first one
|
|
|
|
return shortcuts && shortcuts.length > 0 ? shortcuts[0] : "";
|
|
|
|
};
|