mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Refactors
This commit is contained in:
parent
d3a41cb453
commit
8e4fd83f5c
2 changed files with 46 additions and 41 deletions
|
@ -335,14 +335,21 @@ export class LinearElementEditor {
|
||||||
LinearElementEditor.movePoints(
|
LinearElementEditor.movePoints(
|
||||||
element,
|
element,
|
||||||
selectedPointsIndices.map((pointIndex) => {
|
selectedPointsIndices.map((pointIndex) => {
|
||||||
let p = pointFrom<GlobalPoint>(
|
let newPointPosition = pointFrom<LocalPoint>(
|
||||||
element.x + element.points[pointIndex][0] + deltaX,
|
element.points[pointIndex][0] + deltaX,
|
||||||
element.y + element.points[pointIndex][1] + deltaY,
|
element.points[pointIndex][1] + deltaY,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Check if point dragging is happening
|
||||||
|
if (pointIndex === lastClickedPoint) {
|
||||||
|
let globalNewPointPosition = pointFrom<GlobalPoint>(
|
||||||
|
scenePointerX - linearElementEditor.pointerOffset.x,
|
||||||
|
scenePointerY - linearElementEditor.pointerOffset.y,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
pointIndex === lastClickedPoint &&
|
pointIndex === 0 ||
|
||||||
(pointIndex === 0 || pointIndex === element.points.length - 1)
|
pointIndex === element.points.length - 1
|
||||||
) {
|
) {
|
||||||
const hoveredElement = getHoveredElementForBinding(
|
const hoveredElement = getHoveredElementForBinding(
|
||||||
{
|
{
|
||||||
|
@ -355,13 +362,14 @@ export class LinearElementEditor {
|
||||||
elbowed,
|
elbowed,
|
||||||
elbowed,
|
elbowed,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (hoveredElement) {
|
if (hoveredElement) {
|
||||||
const newPoints = Array.from(element.points);
|
const newPoints = Array.from(element.points);
|
||||||
newPoints[pointIndex] = pointFrom(
|
newPoints[pointIndex] = pointFrom(
|
||||||
element.points[pointIndex][0] + deltaX,
|
element.points[pointIndex][0] + deltaX,
|
||||||
element.points[pointIndex][1] + deltaY,
|
element.points[pointIndex][1] + deltaY,
|
||||||
);
|
);
|
||||||
p = bindPointToSnapToElementOutline(
|
globalNewPointPosition = bindPointToSnapToElementOutline(
|
||||||
{
|
{
|
||||||
...element,
|
...element,
|
||||||
points: newPoints,
|
points: newPoints,
|
||||||
|
@ -372,18 +380,15 @@ export class LinearElementEditor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const newPointPosition: LocalPoint =
|
newPointPosition = LinearElementEditor.createPointAt(
|
||||||
pointIndex === lastClickedPoint
|
|
||||||
? LinearElementEditor.createPointAt(
|
|
||||||
element,
|
element,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
p[0],
|
globalNewPointPosition[0],
|
||||||
p[1],
|
globalNewPointPosition[1],
|
||||||
// p[0] - linearElementEditor.pointerOffset.x,
|
|
||||||
// p[1] - linearElementEditor.pointerOffset.y,
|
|
||||||
event[KEYS.CTRL_OR_CMD] ? null : app.getEffectiveGridSize(),
|
event[KEYS.CTRL_OR_CMD] ? null : app.getEffectiveGridSize(),
|
||||||
)
|
);
|
||||||
: pointFrom(p[0] - element.x, p[1] - element.y);
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
index: pointIndex,
|
index: pointIndex,
|
||||||
point: newPointPosition,
|
point: newPointPosition,
|
||||||
|
|
|
@ -781,7 +781,7 @@ describe("Test Transform", () => {
|
||||||
expect((arrow as ExcalidrawArrowElement).endBinding).toStrictEqual({
|
expect((arrow as ExcalidrawArrowElement).endBinding).toStrictEqual({
|
||||||
elementId: "rect-1",
|
elementId: "rect-1",
|
||||||
focus: -0,
|
focus: -0,
|
||||||
gap: 5,
|
gap: FIXED_BINDING_DISTANCE,
|
||||||
});
|
});
|
||||||
expect(rect.boundElements).toStrictEqual([
|
expect(rect.boundElements).toStrictEqual([
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue