浏览代码

Go to selection mode after adding a shape

vanilla_orig
Christopher Chedeau 5 年前
父节点
当前提交
ab84b5a048
共有 1 个文件被更改,包括 12 次插入1 次删除
  1. 12
    1
      src/index.js

+ 12
- 1
src/index.js 查看文件

@@ -144,6 +144,12 @@ function setSelection(selection) {
144 144
   });
145 145
 }
146 146
 
147
+function clearSelection() {
148
+  elements.forEach(element => {
149
+    element.isSelected = false;
150
+  });
151
+}
152
+
147 153
 function App() {
148 154
   const [draggingElement, setDraggingElement] = React.useState(null);
149 155
   const [elementType, setElementType] = React.useState("selection");
@@ -188,7 +194,11 @@ function App() {
188 194
         <input
189 195
           type="radio"
190 196
           checked={elementType === type}
191
-          onChange={() => setElementType(type)}
197
+          onChange={() => {
198
+            setElementType(type);
199
+            clearSelection();
200
+            drawScene();
201
+          }}
192 202
         />
193 203
         {children}
194 204
       </label>
@@ -247,6 +257,7 @@ function App() {
247 257
             elements.pop();
248 258
             setSelection(draggingElement);
249 259
           }
260
+          setElementType("selection");
250 261
           drawScene();
251 262
         }}
252 263
         onMouseMove={e => {

正在加载...
取消
保存