|
@@ -17,7 +17,7 @@ import { selectGroupsForSelectedElements } from "@excalidraw/element";
|
|
|
|
|
|
import { getContainerElement } from "@excalidraw/element";
|
|
import { getContainerElement } from "@excalidraw/element";
|
|
|
|
|
|
-import { arrayToMap, easeOut } from "@excalidraw/common";
|
|
|
|
|
|
+import { arrayToMap, easeOut, isShallowEqual } from "@excalidraw/common";
|
|
|
|
|
|
import type {
|
|
import type {
|
|
ExcalidrawElement,
|
|
ExcalidrawElement,
|
|
@@ -33,11 +33,18 @@ import { getLassoSelectedElementIds } from "./utils";
|
|
|
|
|
|
import type App from "../components/App";
|
|
import type App from "../components/App";
|
|
|
|
|
|
|
|
+type CanvasTranslate = {
|
|
|
|
+ scrollX: number;
|
|
|
|
+ scrollY: number;
|
|
|
|
+ zoom: number;
|
|
|
|
+};
|
|
|
|
+
|
|
export class LassoTrail extends AnimatedTrail {
|
|
export class LassoTrail extends AnimatedTrail {
|
|
private intersectedElements: Set<ExcalidrawElement["id"]> = new Set();
|
|
private intersectedElements: Set<ExcalidrawElement["id"]> = new Set();
|
|
private enclosedElements: Set<ExcalidrawElement["id"]> = new Set();
|
|
private enclosedElements: Set<ExcalidrawElement["id"]> = new Set();
|
|
private elementsSegments: Map<string, LineSegment<GlobalPoint>[]> | null =
|
|
private elementsSegments: Map<string, LineSegment<GlobalPoint>[]> | null =
|
|
null;
|
|
null;
|
|
|
|
+ private canvasTranslate: CanvasTranslate | null = null;
|
|
private keepPreviousSelection: boolean = false;
|
|
private keepPreviousSelection: boolean = false;
|
|
|
|
|
|
constructor(animationFrameHandler: AnimationFrameHandler, app: App) {
|
|
constructor(animationFrameHandler: AnimationFrameHandler, app: App) {
|
|
@@ -169,7 +176,17 @@ export class LassoTrail extends AnimatedTrail {
|
|
.getCurrentTrail()
|
|
.getCurrentTrail()
|
|
?.originalPoints?.map((p) => pointFrom<GlobalPoint>(p[0], p[1]));
|
|
?.originalPoints?.map((p) => pointFrom<GlobalPoint>(p[0], p[1]));
|
|
|
|
|
|
- if (!this.elementsSegments) {
|
|
|
|
|
|
+ const currentCanvasTranslate: CanvasTranslate = {
|
|
|
|
+ scrollX: this.app.state.scrollX,
|
|
|
|
+ scrollY: this.app.state.scrollY,
|
|
|
|
+ zoom: this.app.state.zoom.value,
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ if (
|
|
|
|
+ !this.elementsSegments ||
|
|
|
|
+ !isShallowEqual(currentCanvasTranslate, this.canvasTranslate ?? {})
|
|
|
|
+ ) {
|
|
|
|
+ this.canvasTranslate = currentCanvasTranslate;
|
|
this.elementsSegments = new Map();
|
|
this.elementsSegments = new Map();
|
|
const visibleElementsMap = arrayToMap(this.app.visibleElements);
|
|
const visibleElementsMap = arrayToMap(this.app.visibleElements);
|
|
for (const element of this.app.visibleElements) {
|
|
for (const element of this.app.visibleElements) {
|