Forráskód Böngészése

Add numeric hotkeys (#380)

* Add numeric hotkeys

* Nit: add space after comma
Jilles Soeters 5 éve
szülő
commit
2a8e562e98
2 módosított fájl, 7 hozzáadás és 5 törlés
  1. 2 2
      src/index.tsx
  2. 5 3
      src/shapes.tsx

+ 2 - 2
src/index.tsx

@@ -433,14 +433,14 @@ export class App extends React.Component<{}, AppState> {
   private renderShapesSwitcher() {
     return (
       <>
-        {SHAPES.map(({ value, icon }) => (
+        {SHAPES.map(({ value, icon }, index) => (
           <ToolIcon
             key={value}
             type="radio"
             icon={icon}
             checked={this.state.elementType === value}
             name="editor-current-shape"
-            title={`${capitalizeString(value)} — ${capitalizeString(value)[0]}`}
+            title={`${capitalizeString(value)} — ${capitalizeString(value)[0]}, ${index + 1}`}
             onChange={() => {
               this.setState({ elementType: value });
               elements = clearSelection(elements);

+ 5 - 3
src/shapes.tsx

@@ -74,12 +74,14 @@ export const SHAPES = [
   }
 ];
 
-export const shapesShortcutKeys = SHAPES.map(shape => shape.value[0]);
+export const shapesShortcutKeys = SHAPES.map((shape, index) => [
+    shape.value[0], (index + 1).toString()]
+).flat(1);
 
 export function findShapeByKey(key: string) {
   const defaultElement = "selection";
-  return SHAPES.reduce((element, shape) => {
-    if (shape.value[0] !== key) return element;
+  return SHAPES.reduce((element, shape, index) => {
+    if (shape.value[0] !== key && key !== (index + 1).toString()) return element;
 
     return shape.value;
   }, defaultElement);