Merge branch 'master' into mtolmacs/fix/arrow-snap-overlap
This commit is contained in:
commit
d5931abbe2
@ -87,11 +87,6 @@ import type {
|
|||||||
PointsPositionUpdates,
|
PointsPositionUpdates,
|
||||||
} from "./types";
|
} from "./types";
|
||||||
|
|
||||||
const editorMidPointsCache: {
|
|
||||||
version: number | null;
|
|
||||||
points: (GlobalPoint | null)[];
|
|
||||||
zoom: number | null;
|
|
||||||
} = { version: null, points: [], zoom: null };
|
|
||||||
export class LinearElementEditor {
|
export class LinearElementEditor {
|
||||||
public readonly elementId: ExcalidrawElement["id"] & {
|
public readonly elementId: ExcalidrawElement["id"] & {
|
||||||
_brand: "excalidrawLinearElementId";
|
_brand: "excalidrawLinearElementId";
|
||||||
@ -558,7 +553,7 @@ export class LinearElementEditor {
|
|||||||
element: NonDeleted<ExcalidrawLinearElement>,
|
element: NonDeleted<ExcalidrawLinearElement>,
|
||||||
elementsMap: ElementsMap,
|
elementsMap: ElementsMap,
|
||||||
appState: InteractiveCanvasAppState,
|
appState: InteractiveCanvasAppState,
|
||||||
): typeof editorMidPointsCache["points"] => {
|
): (GlobalPoint | null)[] => {
|
||||||
const boundText = getBoundTextElement(element, elementsMap);
|
const boundText = getBoundTextElement(element, elementsMap);
|
||||||
|
|
||||||
// Since its not needed outside editor unless 2 pointer lines or bound text
|
// Since its not needed outside editor unless 2 pointer lines or bound text
|
||||||
@ -570,25 +565,7 @@ export class LinearElementEditor {
|
|||||||
) {
|
) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
if (
|
|
||||||
editorMidPointsCache.version === element.version &&
|
|
||||||
editorMidPointsCache.zoom === appState.zoom.value
|
|
||||||
) {
|
|
||||||
return editorMidPointsCache.points;
|
|
||||||
}
|
|
||||||
LinearElementEditor.updateEditorMidPointsCache(
|
|
||||||
element,
|
|
||||||
elementsMap,
|
|
||||||
appState,
|
|
||||||
);
|
|
||||||
return editorMidPointsCache.points!;
|
|
||||||
};
|
|
||||||
|
|
||||||
static updateEditorMidPointsCache = (
|
|
||||||
element: NonDeleted<ExcalidrawLinearElement>,
|
|
||||||
elementsMap: ElementsMap,
|
|
||||||
appState: InteractiveCanvasAppState,
|
|
||||||
) => {
|
|
||||||
const points = LinearElementEditor.getPointsGlobalCoordinates(
|
const points = LinearElementEditor.getPointsGlobalCoordinates(
|
||||||
element,
|
element,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
@ -620,9 +597,8 @@ export class LinearElementEditor {
|
|||||||
midpoints.push(segmentMidPoint);
|
midpoints.push(segmentMidPoint);
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
editorMidPointsCache.points = midpoints;
|
|
||||||
editorMidPointsCache.version = element.version;
|
return midpoints;
|
||||||
editorMidPointsCache.zoom = appState.zoom.value;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static getSegmentMidpointHitCoords = (
|
static getSegmentMidpointHitCoords = (
|
||||||
@ -676,8 +652,11 @@ export class LinearElementEditor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
let index = 0;
|
let index = 0;
|
||||||
const midPoints: typeof editorMidPointsCache["points"] =
|
const midPoints = LinearElementEditor.getEditorMidPoints(
|
||||||
LinearElementEditor.getEditorMidPoints(element, elementsMap, appState);
|
element,
|
||||||
|
elementsMap,
|
||||||
|
appState,
|
||||||
|
);
|
||||||
|
|
||||||
while (index < midPoints.length) {
|
while (index < midPoints.length) {
|
||||||
if (midPoints[index] !== null) {
|
if (midPoints[index] !== null) {
|
||||||
@ -1633,23 +1612,14 @@ export class LinearElementEditor {
|
|||||||
y = midPoint[1] - boundTextElement.height / 2;
|
y = midPoint[1] - boundTextElement.height / 2;
|
||||||
} else {
|
} else {
|
||||||
const index = element.points.length / 2 - 1;
|
const index = element.points.length / 2 - 1;
|
||||||
|
const midSegmentMidpoint = LinearElementEditor.getSegmentMidPoint(
|
||||||
|
element,
|
||||||
|
points[index],
|
||||||
|
points[index + 1],
|
||||||
|
index + 1,
|
||||||
|
elementsMap,
|
||||||
|
);
|
||||||
|
|
||||||
let midSegmentMidpoint = editorMidPointsCache.points[index];
|
|
||||||
if (element.points.length === 2) {
|
|
||||||
midSegmentMidpoint = pointCenter(points[0], points[1]);
|
|
||||||
}
|
|
||||||
if (
|
|
||||||
!midSegmentMidpoint ||
|
|
||||||
editorMidPointsCache.version !== element.version
|
|
||||||
) {
|
|
||||||
midSegmentMidpoint = LinearElementEditor.getSegmentMidPoint(
|
|
||||||
element,
|
|
||||||
points[index],
|
|
||||||
points[index + 1],
|
|
||||||
index + 1,
|
|
||||||
elementsMap,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
x = midSegmentMidpoint[0] - boundTextElement.width / 2;
|
x = midSegmentMidpoint[0] - boundTextElement.width / 2;
|
||||||
y = midSegmentMidpoint[1] - boundTextElement.height / 2;
|
y = midSegmentMidpoint[1] - boundTextElement.height / 2;
|
||||||
}
|
}
|
||||||
|
@ -1723,12 +1723,6 @@ export const actionChangeArrowType = register({
|
|||||||
fixedSegments: null,
|
fixedSegments: null,
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
LinearElementEditor.updateEditorMidPointsCache(
|
|
||||||
newElement,
|
|
||||||
elementsMap,
|
|
||||||
app.state,
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
const elementsMap = app.scene.getNonDeletedElementsMap();
|
const elementsMap = app.scene.getNonDeletedElementsMap();
|
||||||
if (newElement.startBinding) {
|
if (newElement.startBinding) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user