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-11-01 17:29:58 +01:00
|
|
|
export type ShortcutName =
|
|
|
|
| SubtypeOf<
|
|
|
|
ActionName,
|
|
|
|
| "toggleTheme"
|
|
|
|
| "loadScene"
|
|
|
|
| "cut"
|
|
|
|
| "copy"
|
|
|
|
| "paste"
|
|
|
|
| "copyStyles"
|
|
|
|
| "pasteStyles"
|
|
|
|
| "selectAll"
|
|
|
|
| "deleteSelectedElements"
|
|
|
|
| "duplicateSelection"
|
|
|
|
| "sendBackward"
|
|
|
|
| "bringForward"
|
|
|
|
| "sendToBack"
|
|
|
|
| "bringToFront"
|
|
|
|
| "copyAsPng"
|
|
|
|
| "copyAsSvg"
|
|
|
|
| "group"
|
|
|
|
| "ungroup"
|
|
|
|
| "gridMode"
|
|
|
|
| "zenMode"
|
|
|
|
| "stats"
|
|
|
|
| "addToLibrary"
|
|
|
|
| "viewMode"
|
|
|
|
| "flipHorizontal"
|
|
|
|
| "flipVertical"
|
|
|
|
| "hyperlink"
|
|
|
|
| "toggleLock"
|
|
|
|
>
|
|
|
|
| "saveScene"
|
|
|
|
| "imageExport";
|
2020-12-12 23:03:58 +01:00
|
|
|
|
|
|
|
const shortcutMap: Record<ShortcutName, string[]> = {
|
2022-11-02 09:32:21 -04:00
|
|
|
toggleTheme: [getShortcutKey("Shift+Alt+D")],
|
2022-11-01 17:29:58 +01:00
|
|
|
saveScene: [getShortcutKey("CtrlOrCmd+S")],
|
|
|
|
loadScene: [getShortcutKey("CtrlOrCmd+O")],
|
|
|
|
imageExport: [getShortcutKey("CtrlOrCmd+Shift+E")],
|
2020-12-12 23:03:58 +01:00
|
|
|
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")],
|
2022-11-19 18:28:08 +01:00
|
|
|
deleteSelectedElements: [getShortcutKey("Delete")],
|
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")],
|
2022-04-07 12:43:29 +01:00
|
|
|
toggleLock: [getShortcutKey("CtrlOrCmd+Shift+L")],
|
2020-12-12 23:03:58 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
export const getShortcutFromShortcutName = (name: ShortcutName) => {
|
|
|
|
const shortcuts = shortcutMap[name];
|
2022-03-02 01:07:12 -05:00
|
|
|
// if multiple shortcuts available, take the first one
|
2020-12-12 23:03:58 +01:00
|
|
|
return shortcuts && shortcuts.length > 0 ? shortcuts[0] : "";
|
|
|
|
};
|