Преглед на файлове

Allow dragging transparent elements when selected (#508)

* Allow dragging transparent elements when selected

Addresses #339

* Update package.json
Dvir Azulay преди 5 години
родител
ревизия
a856ce06e9
променени са 1 файла, в които са добавени 7 реда и са изтрити 3 реда
  1. 7 3
      src/element/collision.ts

+ 7 - 3
src/element/collision.ts

@@ -8,6 +8,10 @@ import {
   getLinePoints
 } from "./bounds";
 
+function isElementDraggableFromInside(element: ExcalidrawElement): boolean {
+  return element.backgroundColor !== "transparent" || element.isSelected;
+}
+
 export function hitTest(
   element: ExcalidrawElement,
   x: number,
@@ -51,7 +55,7 @@ export function hitTest(
       ty /= t;
     });
 
-    if (element.backgroundColor !== "transparent") {
+    if (isElementDraggableFromInside(element)) {
       return (
         a * tx - (px - lineThreshold) >= 0 && b * ty - (py - lineThreshold) >= 0
       );
@@ -61,7 +65,7 @@ export function hitTest(
   } else if (element.type === "rectangle") {
     const [x1, y1, x2, y2] = getElementAbsoluteCoords(element);
 
-    if (element.backgroundColor !== "transparent") {
+    if (isElementDraggableFromInside(element)) {
       return (
         x > x1 - lineThreshold &&
         x < x2 + lineThreshold &&
@@ -94,7 +98,7 @@ export function hitTest(
       leftY
     ] = getDiamondPoints(element);
 
-    if (element.backgroundColor !== "transparent") {
+    if (isElementDraggableFromInside(element)) {
       // TODO: remove this when we normalize coordinates globally
       if (topY > bottomY) [bottomY, topY] = [topY, bottomY];
       if (rightX < leftX) [leftX, rightX] = [rightX, leftX];