Rotated arrow drag fixes

Signed-off-by: Mark Tolmacs <mark@lazycat.hu>
This commit is contained in:
Mark Tolmacs 2025-03-30 19:43:58 +02:00
parent b2e19055bf
commit 37653484a1

View file

@ -18,6 +18,9 @@ import {
getGridPoint, getGridPoint,
invariant, invariant,
tupleToCoors, tupleToCoors,
debugDrawPoint,
debugClear,
debugDrawBounds,
} from "@excalidraw/common"; } from "@excalidraw/common";
// TODO: remove direct dependency on the scene, should be passed in or injected instead // TODO: remove direct dependency on the scene, should be passed in or injected instead
@ -46,7 +49,9 @@ import {
isBindingEnabled, isBindingEnabled,
} from "./binding"; } from "./binding";
import { import {
getCommonBoundingBox,
getElementAbsoluteCoords, getElementAbsoluteCoords,
getElementBounds,
getElementPointsCoords, getElementPointsCoords,
getMinMaxXYFromCurvePathOps, getMinMaxXYFromCurvePathOps,
} from "./bounds"; } from "./bounds";
@ -332,51 +337,50 @@ export class LinearElementEditor {
const deltaX = newDraggingPointPosition[0] - draggingPoint[0]; const deltaX = newDraggingPointPosition[0] - draggingPoint[0];
const deltaY = newDraggingPointPosition[1] - draggingPoint[1]; const deltaY = newDraggingPointPosition[1] - draggingPoint[1];
debugClear();
LinearElementEditor.movePoints( LinearElementEditor.movePoints(
element, element,
selectedPointsIndices.map((pointIndex) => { selectedPointsIndices.map((pointIndex) => {
let newPointPosition = pointFrom<LocalPoint>( let newPointPosition: LocalPoint =
pointIndex === lastClickedPoint
? LinearElementEditor.createPointAt(
element,
elementsMap,
scenePointerX - linearElementEditor.pointerOffset.x,
scenePointerY - linearElementEditor.pointerOffset.y,
event[KEYS.CTRL_OR_CMD] ? null : app.getEffectiveGridSize(),
)
: pointFrom(
element.points[pointIndex][0] + deltaX, element.points[pointIndex][0] + deltaX,
element.points[pointIndex][1] + deltaY, element.points[pointIndex][1] + deltaY,
); );
// Check if point dragging is happening if (pointIndex === 0 || pointIndex === element.points.length - 1) {
if (pointIndex === lastClickedPoint) { const [, , , , cx, cy] = getElementAbsoluteCoords(
let globalNewPointPosition = pointFrom<GlobalPoint>( element,
scenePointerX - linearElementEditor.pointerOffset.x, elementsMap,
scenePointerY - linearElementEditor.pointerOffset.y, true,
); );
const avoidancePoint = getOutlineAvoidingPoint(
if (
pointIndex === 0 ||
pointIndex === element.points.length - 1
) {
globalNewPointPosition = getOutlineAvoidingPoint(
element, element,
pointRotateRads( pointRotateRads(
pointFrom<GlobalPoint>( pointFrom<GlobalPoint>(
element.x + element.points[pointIndex][0] + deltaX, element.x + newPointPosition[0],
element.y + element.points[pointIndex][1] + deltaY, element.y + newPointPosition[1],
),
pointFrom<GlobalPoint>(
element.x + element.width / 2,
element.y + element.height / 2,
), ),
pointFrom<GlobalPoint>(cx, cy),
element.angle, element.angle,
), ),
pointIndex, pointIndex,
app.scene, app.scene,
app.state.zoom, app.state.zoom,
); );
}
newPointPosition = LinearElementEditor.createPointAt( newPointPosition = LinearElementEditor.createPointAt(
element, element,
elementsMap, elementsMap,
globalNewPointPosition[0], avoidancePoint[0] - linearElementEditor.pointerOffset.x,
globalNewPointPosition[1], avoidancePoint[1] - linearElementEditor.pointerOffset.y,
event[KEYS.CTRL_OR_CMD] ? null : app.getEffectiveGridSize(), null,
); );
} }