Browse Source

添加多选和反选

liwei 1 year ago
parent
commit
f4f5efb931
1 changed files with 28 additions and 6 deletions
  1. 28 6
      src/modules/editor/controllers/SelectCtrl/index.ts

+ 28 - 6
src/modules/editor/controllers/SelectCtrl/index.ts

@@ -476,7 +476,8 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
 
     if (isClick) {
       this._state = MODE_NONE;
-      this.actions.pickComp(this._downClickedCompId);
+      this._selectObjs(this._downClickedCompId?[this._downClickedCompId]:[], e)
+      // this.actions.pickComp(this._downClickedCompId);
     }
 
     if (this._state == MODE_SEL_RECT && !isClick) {
@@ -487,7 +488,8 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
         this._lastSelRect[0] - box.left,
         this._lastSelRect[1] - box.top,
         this._lastSelRect[2],
-        this._lastSelRect[3]
+        this._lastSelRect[3],
+        e
       );
     }
 
@@ -559,11 +561,11 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
     history.submit();
   }
 
-  rectSelect(x: number, y: number, width: number, height: number) {
+  rectSelect(x: number, y: number, width: number, height: number, e:MouseEvent) {
     const childs =
       this.compMap[this.store.currStreamCardId].children.default || [];
     let n = childs.length;
-    const outs = [];
+    const outs:string[] = [];
     while (n--) {
       const o = new CompObject(this.compMap[childs[n]]);
       if (o.testRect({ x, y, w: width, h: height }, true)) {
@@ -571,8 +573,28 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
         outs.push(o.comp.id);
       }
     }
-    this.actions.selectObjs(outs);
-    if (outs.length < 1) {
+    this._selectObjs(outs, e);
+  }
+
+  _selectObjs( outs:string[], e:MouseEvent) {
+
+    let objs = this.store.selected.slice(0);
+    if (e.ctrlKey) {
+      objs.forEach(o=>{
+        if (outs.indexOf(o) == -1) {
+          outs.push(o);
+        }
+      })
+    }
+    let selected = outs;
+    if (e.shiftKey) {//反选
+      selected = [];
+      objs.forEach(o=>{
+         if (outs.indexOf(o) == -1) selected.push(o); 
+      })
+    }
+    this.actions.selectObjs(selected);
+    if (selected.length < 1) {
       this.actions.pickComp(this.store.currStreamCardId);
     }
   }