Browse Source

fix: ensure `s` and `g` shortcuts work on no selection (#3800)

Co-authored-by: dwelle <luzar.david@gmail.com>
vanilla_orig
Jakub Koralewski 3 years ago
parent
commit
ee64a7e264
No account linked to committer's email address
2 changed files with 18 additions and 12 deletions
  1. 17
    11
      src/components/App.tsx
  2. 1
    1
      src/shapes.tsx

+ 17
- 11
src/components/App.tsx View File

156
   getElementsWithinSelection,
156
   getElementsWithinSelection,
157
   getNormalizedZoom,
157
   getNormalizedZoom,
158
   getSelectedElements,
158
   getSelectedElements,
159
+  hasBackground,
159
   isOverScrollBars,
160
   isOverScrollBars,
160
   isSomeElementSelected,
161
   isSomeElementSelected,
161
 } from "../scene";
162
 } from "../scene";
1582
       }
1583
       }
1583
 
1584
 
1584
       if (event.key === KEYS.G || event.key === KEYS.S) {
1585
       if (event.key === KEYS.G || event.key === KEYS.S) {
1585
-        const selectedElements = getSelectedElements(
1586
-          this.scene.getElements(),
1587
-          this.state,
1588
-        );
1589
-        if (selectedElements.length) {
1590
-          if (event.key === KEYS.G) {
1591
-            this.setState({ openPopup: "backgroundColorPicker" });
1592
-          }
1593
-          if (event.key === KEYS.S) {
1594
-            this.setState({ openPopup: "strokeColorPicker" });
1595
-          }
1586
+        if (this.state.elementType === "selection") {
1587
+          return;
1588
+        }
1589
+
1590
+        if (
1591
+          event.key === KEYS.G &&
1592
+          (hasBackground(this.state.elementType) ||
1593
+            getSelectedElements(
1594
+              this.scene.getElements(),
1595
+              this.state,
1596
+            ).some((element) => hasBackground(element.type)))
1597
+        ) {
1598
+          this.setState({ openPopup: "backgroundColorPicker" });
1599
+        }
1600
+        if (event.key === KEYS.S) {
1601
+          this.setState({ openPopup: "strokeColorPicker" });
1596
         }
1602
         }
1597
       }
1603
       }
1598
     },
1604
     },

+ 1
- 1
src/shapes.tsx View File

11
       </svg>
11
       </svg>
12
     ),
12
     ),
13
     value: "selection",
13
     value: "selection",
14
-    key: [KEYS.V, KEYS.S],
14
+    key: KEYS.V,
15
   },
15
   },
16
   {
16
   {
17
     icon: (
17
     icon: (

Loading…
Cancel
Save