Browse Source

修复多选框的回退操作

liwei 1 year ago
parent
commit
4b0873c950

+ 3 - 10
src/modules/editor/controllers/SelectCtrl/ObjsContainer.ts

@@ -255,7 +255,7 @@ export class ObjsContainer {
 
         this.applyChildWidth({scaleX: Width / preW, scaleY: Height/preH})
         this.updateCompState();
-        
+
     }
 
     scaleWidth(x:number) {
@@ -290,16 +290,9 @@ export class ObjsContainer {
         let n = selected.length;
         while (n--) {
             let child = selected[n];
-            child.updateTransform();
-
-            //世界坐标
-            child.transform.setFromMatrix(child.worldTransform);
-            child.parent = null;
-            child.transform._parentID = -1;
-            child.updateTransform();
-            child._boundsID = -2;
-            child._lastBoundsID = 0;
+            this.parent.removeChildWorldNoChange(child)
         }
+        this.selected = [];
     }
 
     updateCompState() {

+ 21 - 3
src/modules/editor/controllers/SelectCtrl/index.ts

@@ -101,13 +101,19 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
   _mouseDownFlag = "";
   _mouseDownTimestamp = 0;
 
+  _containers:Map<string, ObjsContainer> = new Map();
+
   _updateSelects() {
     const selecteds = this.store.selected;
+    const ObjC = this._containers.get(this.store.selectId)
     let objs = [];
     for (let item of selecteds) {
         objs.push( new CompObject(this.compMap[item]) )
     }
-    this.selecteObjs(objs);
+    this.selecteObjs(objs, ObjC);
+    if (this.store.selectId) {
+        this._containers.set(this.store.selectId, this.objContainer as ObjsContainer);
+    }
   }
 
   onDocMouseDown(e: MouseEvent) {
@@ -294,6 +300,7 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
   movingMousemove(e: MouseEvent) {
     const objContainer = this.objContainer as ObjsContainer;
 
+    objContainer.setPivot(0);
     objContainer.translate(
       e.clientX - this._movePreClientX,
       e.clientY - this._movePreClientY
@@ -396,6 +403,7 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
       this._selCanvaseSize.h
     );
     this.upgateGizmoStyle();
+    this.helper.extendStreamCard(this.store.currStreamCardId);
   }
   moveMouseUp(e: MouseEvent) {
     const history = this.controls.historyCtrl.history;
@@ -407,24 +415,31 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
     const initX = this._initMovePos.x,
       initY = this._initMovePos.y;
 
+      obj.setPivot(0);
+
     history.record({
       undo: () => {
         console.log("undo ");
-
         const currObj = this.objContainer as ObjsContainer;
+        currObj.setPivot(0);
         currObj.parent.x = initX;
         currObj.parent.y = initY;
         currObj.parent.updateTransform();
         currObj.updateCompState();
+       
         this.upgateGizmoStyle();
+        this.helper.extendStreamCard(this.store.currStreamCardId);
       },
       redo: () => {
+      
         const currObj = this.objContainer as ObjsContainer;
+        currObj.setPivot(0);
         currObj.parent.x = lastX;
         currObj.parent.y = lastY;
         currObj.parent.updateTransform();
         currObj.updateCompState();
         this.upgateGizmoStyle();
+        this.helper.extendStreamCard(this.store.currStreamCardId);
       },
     } as any);
     history.submit();
@@ -446,7 +461,6 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
   }
   
   upgateGizmoStyle() {
-    this.helper.extendStreamCard(this.store.currStreamCardId);
     this.transferStyle.mode = this._state;
 
     if (this.selected.length < 1) {
@@ -687,6 +701,7 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
         this.objContainer?.setPivot(0);
         this.objContainer?.updateCompState();
         this.upgateGizmoStyle();
+        this.helper.extendStreamCard(this.store.currStreamCardId);
       },
 
       redo: () => {
@@ -697,6 +712,7 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
         this.objContainer?.setPivot(0);
         this.objContainer?.updateCompState();
         this.upgateGizmoStyle();
+        this.helper.extendStreamCard(this.store.currStreamCardId);
       },
     } as any);
     history.submit();
@@ -824,6 +840,7 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
           this.objContainer?.updateCompState();
 
           this.upgateGizmoStyle();
+          this.helper.extendStreamCard(this.store.currStreamCardId);
         },
         redo: () => {
           console.log("redo ");
@@ -832,6 +849,7 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
           this.objContainer?.setPivot(0);
           this.objContainer?.updateCompState();
           this.upgateGizmoStyle();
+          this.helper.extendStreamCard(this.store.currStreamCardId);
         },
       } as any);
       history.submit();

+ 2 - 3
src/modules/editor/module/actions/edit.ts

@@ -104,9 +104,8 @@ export const editActions = EditorModule.action({
   },
   
    async selectObjs(ids: string[]) {
-
-    console.log( "this.store.selected", this.store.selected )
-      this.store.selected = ids;
+     this.store.selected = ids;
+     this.store.selectId = ids.length > 0 ? (Date.now() + "") : ""
    },
 
   // 添加组件到画布

+ 6 - 1
src/modules/editor/module/actions/init.ts

@@ -13,7 +13,12 @@ export const initActions = EditorModule.action({
     this.controls.compUICtrl.init();
 
     createProxyEffect(this.store, (type, paths, value, oldValue) => {
-      if (paths[0] === "designData" || paths[0] === "currCompId" || paths[0] === "selected" || paths[0] === "currStreamCardId") {
+      if (paths[0] === "designData" || 
+          paths[0] === "currCompId" || 
+          paths[0] === "selected" || 
+          paths[0] === "currStreamCardId" ||
+          paths[0] === "selectId"
+          ) {
         historyCtrl.record(this.store, type, paths, value, oldValue);
       }
     });

+ 1 - 0
src/modules/editor/module/stores/index.ts

@@ -18,6 +18,7 @@ export const store = EditorModule.store({
   
 
     selected: [] as string[], //选中的组件
+    selectId: "",    //选中的id唯一标识一次选中
   }),
   getters: {
     isEditMode(): boolean {