2020-12-12 23:03:58 +01:00
|
|
|
import { t } from "../i18n";
|
|
|
|
import { isDarwin } from "../keys";
|
|
|
|
import { getShortcutKey } from "../utils";
|
2022-02-21 17:44:28 +05:30
|
|
|
import { ActionName } from "./types";
|
2020-12-12 23:03:58 +01:00
|
|
|
|
2022-02-21 17:44:28 +05:30
|
|
|
export type ShortcutName = SubtypeOf<
|
|
|
|
ActionName,
|
2020-12-12 23:03:58 +01:00
|
|
|
| "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"
|
2021-02-02 02:26:42 +05:30
|
|
|
| "addToLibrary"
|
2021-03-26 11:45:08 -04:00
|
|
|
| "viewMode"
|
|
|
|
| "flipHorizontal"
|
2022-02-03 20:34:59 +05:30
|
|
|
| "flipVertical"
|
2022-02-21 17:44:28 +05:30
|
|
|
| "hyperlink"
|
|
|
|
>;
|
2020-12-12 23:03:58 +01:00
|
|
|
|
|
|
|
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")],
|
2021-05-12 04:57:35 -04:00
|
|
|
stats: [getShortcutKey("Alt+/")],
|
2020-12-12 23:03:58 +01:00
|
|
|
addToLibrary: [],
|
2021-03-26 11:45:08 -04:00
|
|
|
flipHorizontal: [getShortcutKey("Shift+H")],
|
|
|
|
flipVertical: [getShortcutKey("Shift+V")],
|
2021-02-02 02:26:42 +05:30
|
|
|
viewMode: [getShortcutKey("Alt+R")],
|
2022-02-21 17:44:28 +05:30
|
|
|
hyperlink: [getShortcutKey("CtrlOrCmd+K")],
|
2020-12-12 23:03:58 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
export const getShortcutFromShortcutName = (name: ShortcutName) => {
|
|
|
|
const shortcuts = shortcutMap[name];
|
|
|
|
// if multiple shortcuts availiable, take the first one
|
|
|
|
return shortcuts && shortcuts.length > 0 ? shortcuts[0] : "";
|
|
|
|
};
|