Virtual whiteboard for sketching hand-drawn like diagrams
fix: update cached segments when visible area changes (#9512)
Ryan Di35bb449a4bb6
diff --git a/packages/excalidraw/lasso/index.ts b/packages/excalidraw/lasso/index.tsindex 41e6b2080b..163a8b7a98 100644--- a/packages/excalidraw/lasso/index.ts+++ b/packages/excalidraw/lasso/index.ts@@ -17,7 +17,7 @@ import { selectGroupsForSelectedElements } from "@excalidraw/element";import { getContainerElement } from "@excalidraw/element";-import { arrayToMap, easeOut } from "@excalidraw/common";+import { arrayToMap, easeOut, isShallowEqual } from "@excalidraw/common";import type {ExcalidrawElement,@@ -33,11 +33,18 @@ import { getLassoSelectedElementIds } from "./utils";import type App from "../components/App";+type CanvasTranslate = {+ scrollX: number;+ scrollY: number;+ zoom: number;+};+export class LassoTrail extends AnimatedTrail {private intersectedElements: Set<ExcalidrawElement["id"]> = new Set();private enclosedElements: Set<ExcalidrawElement["id"]> = new Set();private elementsSegments: Map<string, LineSegment<GlobalPoint>[]> | null =null;+ private canvasTranslate: CanvasTranslate | null = null;private keepPreviousSelection: boolean = false;constructor(animationFrameHandler: AnimationFrameHandler, app: App) {@@ -169,7 +176,17 @@ export class LassoTrail extends AnimatedTrail {.getCurrentTrail()?.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();const visibleElementsMap = arrayToMap(this.app.visibleElements);for (const element of this.app.visibleElements) {