fix for #1106 - Weird behavior when resize + shift a 2-point li… (#1152)

Co-authored-by: dwelle <luzar.david@gmail.com>
This commit is contained in:
José Quinto 2020-04-02 10:46:05 +01:00 committed by GitHub
parent 65be7973be
commit 8fea75b84f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1864,39 +1864,31 @@ export class App extends React.Component<any, AppState> {
pointerY: number, pointerY: number,
perfect: boolean, perfect: boolean,
) => { ) => {
const p1 = element.points[pointIndex]; const [px, py] = element.points[pointIndex];
if (perfect) { let x = element.x + deltaX;
const absPx = p1[0] + element.x; let y = element.y + deltaY;
const absPy = p1[1] + element.y; let pointX = px - deltaX;
let pointY = py - deltaY;
if (perfect) {
const { width, height } = getPerfectElementSize( const { width, height } = getPerfectElementSize(
element.type, element.type,
pointerX - element.x - p1[0], px + element.x - pointerX,
pointerY - element.y - p1[1], py + element.y - pointerY,
); );
x = px + element.x - width;
const dx = element.x + width + p1[0]; y = py + element.y - height;
const dy = element.y + height + p1[1]; pointX = width;
mutateElement(element, { pointY = height;
x: dx,
y: dy,
points: element.points.map((point, i) =>
i === pointIndex
? ([absPx - element.x, absPy - element.y] as const)
: point,
),
});
} else {
mutateElement(element, {
x: element.x + deltaX,
y: element.y + deltaY,
points: element.points.map((point, i) =>
i === pointIndex
? ([p1[0] - deltaX, p1[1] - deltaY] as const)
: point,
),
});
} }
mutateElement(element, {
x,
y,
points: element.points.map((point, i) =>
i === pointIndex ? ([pointX, pointY] as const) : point,
),
});
}; };
const arrowResizeEnd = ( const arrowResizeEnd = (
@ -1908,7 +1900,7 @@ export class App extends React.Component<any, AppState> {
pointerY: number, pointerY: number,
perfect: boolean, perfect: boolean,
) => { ) => {
const p1 = element.points[pointIndex]; const [px, py] = element.points[pointIndex];
if (perfect) { if (perfect) {
const { width, height } = getPerfectElementSize( const { width, height } = getPerfectElementSize(
element.type, element.type,
@ -1923,9 +1915,7 @@ export class App extends React.Component<any, AppState> {
} else { } else {
mutateElement(element, { mutateElement(element, {
points: element.points.map((point, i) => points: element.points.map((point, i) =>
i === pointIndex i === pointIndex ? ([px + deltaX, py + deltaY] as const) : point,
? ([p1[0] + deltaX, p1[1] + deltaY] as const)
: point,
), ),
}); });
} }