bianjiang 1 year ago
parent
commit
bef8d626a8
1 changed files with 20 additions and 25 deletions
  1. 20 25
      src/modules/editor/controllers/SelectCtrl/assistRulerCtrl.ts

+ 20 - 25
src/modules/editor/controllers/SelectCtrl/assistRulerCtrl.ts

@@ -30,19 +30,17 @@ export class AssistRulerCtrl {
     let n = this.rulers.length;
     while (n--) {
       const item = this.rulers[n];
-      if (item.horz != undefined && Math.abs(item.horz - y * 2) < 4) {
+      if (item.horz != undefined && Math.abs(item.horz - y * 2) < 8) {
         this._currDragItem = item;
         break;
-      } else if (item.verz != undefined && Math.abs(item.verz - x * 2) < 4) {
+      } else if (item.verz != undefined && Math.abs(item.verz - x * 2) < 8) {
         this._currDragItem = item;
         break;
       }
     }
-
-    console.log("test=>", this._currDragItem);
-    if (this._currCursor) {
-      this._currCursor = document.body.style.cursor;
-    }
+    // if (this._currCursor) {
+    //   this._currCursor = document.body.style.cursor;
+    // }
     return !!this._currDragItem;
   }
 
@@ -57,24 +55,23 @@ export class AssistRulerCtrl {
     const pageBox = pageViewPort.getBoundingClientRect();
     const cx = e.clientX - pageBox.left;
     const cy = e.clientY - pageBox.top;
-    if (
-      Math.floor(cx) < -40 ||
-      Math.floor(cy) < -40 ||
-      e.clientX - pageBox.right > 40 ||
-      e.clientY - pageBox.bottom > 40
-    ) {
-      return;
-    }
+    // if (
+    //   Math.floor(cx) < -40 ||
+    //   Math.floor(cy) < -40 ||
+    //   e.clientX - pageBox.right > 40 ||
+    //   e.clientY - pageBox.bottom > 40
+    // ) {
+    //   return;
+    // }
 
     if (it.verz != undefined) {
       it.verz = cx * 2;
-      document.body.style.cursor = "ew-resize";
+      //   document.body.style.cursor = "ew-resize";
     } else {
       it.horz = cy * 2;
-      document.body.style.cursor = "ns-resize";
+      //   document.body.style.cursor = "ns-resize";
     }
 
-    console.log(it);
     this.draw();
   }
 
@@ -188,16 +185,14 @@ export class AssistRulerCtrl {
     }
     const viewPort = this.ctrl.pageEl as HTMLElement;
     const box = viewPort.getBoundingClientRect();
-
-    if (
-      e.clientX - box.left < -20 ||
-      e.clientY - box.top < -20 ||
-      e.clientY - box.bottom > 20 ||
-      e.clientX - box.right > 20
-    ) {
+    const currDragItem = this._currAddingRuler;
+    const verz = currDragItem.verz || 0;
+    const horz = currDragItem.horz || 0;
+    if (verz < 0 || horz < 0 || verz > box.width * 2 || horz > box.height * 2) {
       this._currAddingRuler = undefined;
       return;
     }
+
     this.rulers.push({ ...this._currAddingRuler });
 
     console.log("rulerLineMouseUp=>", e.clientY);