Compare commits
2 Commits
master
...
dwelle/0.1
Author | SHA1 | Date | |
---|---|---|---|
![]() |
d878a2f647 | ||
![]() |
de983c1d93 |
@ -13,6 +13,7 @@ import { Point } from "../types";
|
|||||||
import { generateRoughOptions } from "../scene/Shape";
|
import { generateRoughOptions } from "../scene/Shape";
|
||||||
import {
|
import {
|
||||||
isArrowElement,
|
isArrowElement,
|
||||||
|
isBoundToContainer,
|
||||||
isFreeDrawElement,
|
isFreeDrawElement,
|
||||||
isLinearElement,
|
isLinearElement,
|
||||||
isTextElement,
|
isTextElement,
|
||||||
@ -22,6 +23,7 @@ import { getBoundTextElement, getContainerElement } from "./textElement";
|
|||||||
import { LinearElementEditor } from "./linearElementEditor";
|
import { LinearElementEditor } from "./linearElementEditor";
|
||||||
import { Mutable } from "../utility-types";
|
import { Mutable } from "../utility-types";
|
||||||
import { ShapeCache } from "../scene/ShapeCache";
|
import { ShapeCache } from "../scene/ShapeCache";
|
||||||
|
import Scene from "../scene/Scene";
|
||||||
|
|
||||||
export type RectangleBox = {
|
export type RectangleBox = {
|
||||||
x: number;
|
x: number;
|
||||||
@ -53,16 +55,29 @@ export class ElementBounds {
|
|||||||
static getBounds(element: ExcalidrawElement) {
|
static getBounds(element: ExcalidrawElement) {
|
||||||
const cachedBounds = ElementBounds.boundsCache.get(element);
|
const cachedBounds = ElementBounds.boundsCache.get(element);
|
||||||
|
|
||||||
if (cachedBounds?.version && cachedBounds.version === element.version) {
|
if (
|
||||||
|
cachedBounds?.version &&
|
||||||
|
cachedBounds.version === element.version &&
|
||||||
|
// we don't invalidate cache when we update containers and not labels,
|
||||||
|
// which is causing problems down the line. Fix TBA.
|
||||||
|
!isBoundToContainer(element)
|
||||||
|
) {
|
||||||
return cachedBounds.bounds;
|
return cachedBounds.bounds;
|
||||||
}
|
}
|
||||||
|
|
||||||
const bounds = ElementBounds.calculateBounds(element);
|
const bounds = ElementBounds.calculateBounds(element);
|
||||||
|
|
||||||
ElementBounds.boundsCache.set(element, {
|
// hack to ensure that downstream checks could retrieve element Scene
|
||||||
version: element.version,
|
// so as to have correctly calculated bounds
|
||||||
bounds,
|
// FIXME remove when we get rid of all the id:Scene / element:Scene mapping
|
||||||
});
|
const shouldCache = Scene.getScene(element);
|
||||||
|
|
||||||
|
if (shouldCache) {
|
||||||
|
ElementBounds.boundsCache.set(element, {
|
||||||
|
version: element.version,
|
||||||
|
bounds,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return bounds;
|
return bounds;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user