mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
New simple arrows stick to outline as well
This commit is contained in:
parent
8e4fd83f5c
commit
df1f89efcd
2 changed files with 57 additions and 25 deletions
|
@ -238,6 +238,43 @@ export class LinearElementEditor {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static getOutlineAvoidingPoint(
|
||||||
|
element: NonDeleted<ExcalidrawLinearElement>,
|
||||||
|
coords: { x: number; y: number },
|
||||||
|
pointIndex: number,
|
||||||
|
app: AppClassProperties,
|
||||||
|
): GlobalPoint {
|
||||||
|
const elbowed = isElbowArrow(element);
|
||||||
|
const hoveredElement = getHoveredElementForBinding(
|
||||||
|
coords,
|
||||||
|
app.scene.getNonDeletedElements(),
|
||||||
|
app.scene.getNonDeletedElementsMap(),
|
||||||
|
app.state.zoom,
|
||||||
|
elbowed,
|
||||||
|
elbowed,
|
||||||
|
);
|
||||||
|
const p = pointFrom<GlobalPoint>(coords.x, coords.y);
|
||||||
|
|
||||||
|
if (hoveredElement) {
|
||||||
|
const newPoints = Array.from(element.points);
|
||||||
|
newPoints[pointIndex] = pointFrom<LocalPoint>(
|
||||||
|
p[0] - element.x,
|
||||||
|
p[1] - element.y,
|
||||||
|
);
|
||||||
|
|
||||||
|
return bindPointToSnapToElementOutline(
|
||||||
|
{
|
||||||
|
...element,
|
||||||
|
points: newPoints,
|
||||||
|
},
|
||||||
|
hoveredElement,
|
||||||
|
pointIndex === 0 ? "start" : "end",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns whether point was dragged
|
* @returns whether point was dragged
|
||||||
*/
|
*/
|
||||||
|
@ -351,33 +388,16 @@ export class LinearElementEditor {
|
||||||
pointIndex === 0 ||
|
pointIndex === 0 ||
|
||||||
pointIndex === element.points.length - 1
|
pointIndex === element.points.length - 1
|
||||||
) {
|
) {
|
||||||
const hoveredElement = getHoveredElementForBinding(
|
globalNewPointPosition =
|
||||||
{
|
LinearElementEditor.getOutlineAvoidingPoint(
|
||||||
x: scenePointerX,
|
element,
|
||||||
y: scenePointerY,
|
|
||||||
},
|
|
||||||
app.scene.getNonDeletedElements(),
|
|
||||||
app.scene.getNonDeletedElementsMap(),
|
|
||||||
app.state.zoom,
|
|
||||||
elbowed,
|
|
||||||
elbowed,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (hoveredElement) {
|
|
||||||
const newPoints = Array.from(element.points);
|
|
||||||
newPoints[pointIndex] = pointFrom(
|
|
||||||
element.points[pointIndex][0] + deltaX,
|
|
||||||
element.points[pointIndex][1] + deltaY,
|
|
||||||
);
|
|
||||||
globalNewPointPosition = bindPointToSnapToElementOutline(
|
|
||||||
{
|
{
|
||||||
...element,
|
x: element.x + element.points[pointIndex][0] + deltaX,
|
||||||
points: newPoints,
|
y: element.y + element.points[pointIndex][1] + deltaY,
|
||||||
},
|
},
|
||||||
hoveredElement,
|
pointIndex,
|
||||||
pointIndex === 0 ? "start" : "end",
|
app,
|
||||||
);
|
);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
newPointPosition = LinearElementEditor.createPointAt(
|
newPointPosition = LinearElementEditor.createPointAt(
|
||||||
|
|
|
@ -8602,10 +8602,22 @@ class App extends React.Component<AppProps, AppState> {
|
||||||
points.length === 2 ||
|
points.length === 2 ||
|
||||||
(points.length > 1 && isElbowArrow(newElement))
|
(points.length > 1 && isElbowArrow(newElement))
|
||||||
) {
|
) {
|
||||||
|
const globalPoint = LinearElementEditor.getOutlineAvoidingPoint(
|
||||||
|
newElement,
|
||||||
|
{ x: newElement.x + dx, y: newElement.y + dy },
|
||||||
|
1,
|
||||||
|
this,
|
||||||
|
);
|
||||||
mutateElement(
|
mutateElement(
|
||||||
newElement,
|
newElement,
|
||||||
{
|
{
|
||||||
points: [...points.slice(0, -1), pointFrom<LocalPoint>(dx, dy)],
|
points: [
|
||||||
|
...points.slice(0, -1),
|
||||||
|
pointFrom<LocalPoint>(
|
||||||
|
globalPoint[0] - newElement.x,
|
||||||
|
globalPoint[1] - newElement.y,
|
||||||
|
),
|
||||||
|
],
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
{ isDragging: true },
|
{ isDragging: true },
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue