[skip ci] No jumping at the beginning

This commit is contained in:
Mark Tolmacs 2025-03-27 20:12:01 +01:00
parent 4184103eb0
commit 05d8ce55e4
2 changed files with 10 additions and 59 deletions

View file

@ -98,28 +98,6 @@ const _newElementBase = <T extends ExcalidrawElement>(
...rest ...rest
}: ElementConstructorOpts & Omit<Partial<ExcalidrawGenericElement>, "type">, }: ElementConstructorOpts & Omit<Partial<ExcalidrawGenericElement>, "type">,
) => { ) => {
// NOTE (mtolmacs): This is a temporary check to detect extremely large
// element position or sizing
if (
x < -1e6 ||
x > 1e6 ||
y < -1e6 ||
y > 1e6 ||
width < -1e6 ||
width > 1e6 ||
height < -1e6 ||
height > 1e6
) {
console.error("New element size or position is too large", {
x,
y,
width,
height,
// @ts-ignore
points: rest.points,
});
}
// assign type to guard against excess properties // assign type to guard against excess properties
const element: Merge<ExcalidrawGenericElement, { type: T["type"] }> = { const element: Merge<ExcalidrawGenericElement, { type: T["type"] }> = {
id: rest.id || randomId(), id: rest.id || randomId(),

View file

@ -16,7 +16,6 @@ import {
vectorSubtract, vectorSubtract,
vectorDot, vectorDot,
vectorNormalize, vectorNormalize,
lineSegment,
} from "@excalidraw/math"; } from "@excalidraw/math";
import { isPointInShape } from "@excalidraw/utils/collision"; import { isPointInShape } from "@excalidraw/utils/collision";
import { getSelectionBoxShape } from "@excalidraw/utils/shape"; import { getSelectionBoxShape } from "@excalidraw/utils/shape";
@ -120,7 +119,6 @@ import {
updateBoundElements, updateBoundElements,
getSuggestedBindingsForArrows, getSuggestedBindingsForArrows,
getOutlineAvoidingPoint, getOutlineAvoidingPoint,
FIXED_BINDING_DISTANCE,
} from "@excalidraw/element/binding"; } from "@excalidraw/element/binding";
import { LinearElementEditor } from "@excalidraw/element/linearElementEditor"; import { LinearElementEditor } from "@excalidraw/element/linearElementEditor";
@ -232,7 +230,6 @@ import {
hitElementBoundText, hitElementBoundText,
hitElementBoundingBoxOnly, hitElementBoundingBoxOnly,
hitElementItself, hitElementItself,
intersectElementWithLineSegment,
} from "@excalidraw/element/collision"; } from "@excalidraw/element/collision";
import { getVisibleSceneBounds } from "@excalidraw/element/bounds"; import { getVisibleSceneBounds } from "@excalidraw/element/bounds";
@ -7830,43 +7827,19 @@ class App extends React.Component<AppProps, AppState> {
this.state.currentItemArrowType === ARROW_TYPE.elbow ? [] : null, this.state.currentItemArrowType === ARROW_TYPE.elbow ? [] : null,
}); });
const hoveredElement = getHoveredElementForBinding( const [x, y] = getOutlineAvoidingPoint(
{ x: gridX, y: gridY }, arrow,
this.scene.getNonDeletedElements(), pointFrom<GlobalPoint>(gridX, gridY),
this.scene.getNonDeletedElementsMap(), 0,
this.scene,
this.state.zoom, this.state.zoom,
true,
this.state.currentItemArrowType === ARROW_TYPE.elbow,
); );
if (hoveredElement) { element = {
[arrow.x, arrow.y] = ...arrow,
intersectElementWithLineSegment( x,
hoveredElement, y,
lineSegment( };
pointFrom<GlobalPoint>(gridX, gridY),
pointFrom<GlobalPoint>(
gridX,
hoveredElement.y + hoveredElement.height / 2,
),
),
2 * FIXED_BINDING_DISTANCE,
)[0] ??
intersectElementWithLineSegment(
hoveredElement,
lineSegment(
pointFrom<GlobalPoint>(gridX, gridY),
pointFrom<GlobalPoint>(
hoveredElement.x + hoveredElement.width / 2,
gridY,
),
),
2 * FIXED_BINDING_DISTANCE,
)[0] ??
pointFrom<GlobalPoint>(gridX, gridY);
}
element = arrow;
} else { } else {
element = newLinearElement({ element = newLinearElement({
type: elementType, type: elementType,