Ver código fonte

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

Co-authored-by: dwelle <luzar.david@gmail.com>
vanilla_orig
Jakub Koralewski 3 anos atrás
pai
commit
ee64a7e264
Nenhuma conta vinculada ao e-mail do autor do commit
2 arquivos alterados com 18 adições e 12 exclusões
  1. 17
    11
      src/components/App.tsx
  2. 1
    1
      src/shapes.tsx

+ 17
- 11
src/components/App.tsx Ver arquivo

@@ -156,6 +156,7 @@ import {
156 156
   getElementsWithinSelection,
157 157
   getNormalizedZoom,
158 158
   getSelectedElements,
159
+  hasBackground,
159 160
   isOverScrollBars,
160 161
   isSomeElementSelected,
161 162
 } from "../scene";
@@ -1582,17 +1583,22 @@ class App extends React.Component<AppProps, AppState> {
1582 1583
       }
1583 1584
 
1584 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 Ver arquivo

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

Carregando…
Cancelar
Salvar