From dc1f6c4d4cee36f1f3151117a7bb26328c5dc4c5 Mon Sep 17 00:00:00 2001 From: David Luzar Date: Fri, 24 Jul 2020 15:47:46 +0200 Subject: [PATCH] change selection/line/draw shortcut defaults (#1953) --- src/components/Actions.tsx | 8 +++++--- src/components/App.tsx | 7 +++---- src/components/ShortcutsDialog.tsx | 9 ++++++--- src/shapes.tsx | 26 ++++++++++++++------------ 4 files changed, 28 insertions(+), 22 deletions(-) diff --git a/src/components/Actions.tsx b/src/components/Actions.tsx index 144f5539..8c06af08 100644 --- a/src/components/Actions.tsx +++ b/src/components/Actions.tsx @@ -104,9 +104,11 @@ export const ShapesSwitcher = ({ <> {SHAPES.map(({ value, icon, key }, index) => { const label = t(`toolBar.${value}`); - const shortcut = `${capitalizeString(key)} ${t("shortcutsDialog.or")} ${ - index + 1 - }`; + const letter = typeof key === "string" ? key : key[0]; + const letterShortcut = /[a-z]/.test(letter) ? letter : `Shift+${letter}`; + const shortcut = `${capitalizeString(letterShortcut)} ${t( + "shortcutsDialog.or", + )} ${index + 1}`; return ( { this.setState({ isLibraryOpen: !this.state.isLibraryOpen }); } - const shape = findShapeByKey(event.key); - if (isArrowKey(event.key)) { const step = (this.state.gridSize && @@ -1444,7 +1442,8 @@ class App extends React.Component { !event.metaKey && this.state.draggingElement === null ) { - if (shapesShortcutKeys.includes(event.key.toLowerCase())) { + const shape = findShapeByKey(event.key); + if (shape) { this.selectShapeTool(shape); } else if (event.key === "q") { this.toggleLock(); diff --git a/src/components/ShortcutsDialog.tsx b/src/components/ShortcutsDialog.tsx index 2f90eddc..40d812e4 100644 --- a/src/components/ShortcutsDialog.tsx +++ b/src/components/ShortcutsDialog.tsx @@ -178,13 +178,16 @@ export const ShortcutsDialog = ({ onClose }: { onClose?: () => void }) => { - + - - + + ), value: "selection", - key: "s", + key: ["v", "s"], }, { icon: ( @@ -68,7 +68,7 @@ export const SHAPES = [ ), value: "line", - key: "l", + key: ["p", "l"], }, { icon: ( @@ -81,7 +81,7 @@ export const SHAPES = [ ), value: "draw", - key: "x", + key: ["P", "x"], }, { icon: ( @@ -95,12 +95,14 @@ export const SHAPES = [ }, ] as const; -export const shapesShortcutKeys = SHAPES.map((shape, index) => [ - shape.key, - (index + 1).toString(), -]).flat(1); - -export const findShapeByKey = (key: string) => - SHAPES.find((shape, index) => { - return shape.key === key.toLowerCase() || key === (index + 1).toString(); - })?.value || "selection"; +export const findShapeByKey = (key: string) => { + const shape = SHAPES.find((shape, index) => { + return ( + key === (index + 1).toString() || + (typeof shape.key === "string" + ? shape.key === key + : (shape.key as readonly string[]).includes(key)) + ); + }); + return shape?.value || null; +};