From 8e6d55cf7583cfc22795ae2b2b1114e7beaaf507 Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Sat, 28 Mar 2020 18:08:21 -0700 Subject: [PATCH] Fix corner resize for multi-point arrows (#1105) The logic to support it was not implemented. This is not the prettiest way to solve it in the world but it does work. Some more refactoring here is probably warranted. Fixes #1039 --- src/components/App.tsx | 75 +++++++++++++++++++++++++------- src/element/handlerRectangles.ts | 7 --- 2 files changed, 59 insertions(+), 23 deletions(-) diff --git a/src/components/App.tsx b/src/components/App.tsx index c3764310..35687829 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -1964,15 +1964,26 @@ export class App extends React.Component { } resizeArrowFn(element, 1, deltaX, deltaY, x, y, event.shiftKey); } else { + const width = element.width - deltaX; + const height = event.shiftKey + ? element.width + : element.height - deltaY; mutateElement(element, { x: element.x + deltaX, y: event.shiftKey ? element.y + element.height - element.width : element.y + deltaY, - width: element.width - deltaX, - height: event.shiftKey - ? element.width - : element.height - deltaY, + width, + height, + ...(isLinearElement(element) && width >= 0 && height >= 0 + ? { + points: rescalePoints( + 0, + width, + rescalePoints(1, height, element.points), + ), + } + : {}), }); } break; @@ -1988,13 +1999,23 @@ export class App extends React.Component { } resizeArrowFn(element, 1, deltaX, deltaY, x, y, event.shiftKey); } else { - const nextWidth = element.width + deltaX; + const width = element.width + deltaX; + const height = event.shiftKey ? width : element.height - deltaY; mutateElement(element, { y: event.shiftKey - ? element.y + element.height - nextWidth + ? element.y + element.height - width : element.y + deltaY, - width: nextWidth, - height: event.shiftKey ? nextWidth : element.height - deltaY, + width, + height, + ...(isLinearElement(element) && width >= 0 && height >= 0 + ? { + points: rescalePoints( + 0, + width, + rescalePoints(1, height, element.points), + ), + } + : {}), }); } break; @@ -2010,12 +2031,23 @@ export class App extends React.Component { } resizeArrowFn(element, 1, deltaX, deltaY, x, y, event.shiftKey); } else { + const width = element.width - deltaX; + const height = event.shiftKey + ? element.width + : element.height + deltaY; mutateElement(element, { x: element.x + deltaX, - width: element.width - deltaX, - height: event.shiftKey - ? element.width - : element.height + deltaY, + width, + height, + ...(isLinearElement(element) && width >= 0 && height >= 0 + ? { + points: rescalePoints( + 0, + width, + rescalePoints(1, height, element.points), + ), + } + : {}), }); } break; @@ -2031,11 +2063,22 @@ export class App extends React.Component { } resizeArrowFn(element, 1, deltaX, deltaY, x, y, event.shiftKey); } else { + const width = element.width + deltaX; + const height = event.shiftKey + ? element.width + : element.height + deltaY; mutateElement(element, { - width: element.width + deltaX, - height: event.shiftKey - ? element.width - : element.height + deltaY, + width, + height, + ...(isLinearElement(element) && width >= 0 && height >= 0 + ? { + points: rescalePoints( + 0, + width, + rescalePoints(1, height, element.points), + ), + } + : {}), }); } break; diff --git a/src/element/handlerRectangles.ts b/src/element/handlerRectangles.ts index 414070b8..9e610d3a 100644 --- a/src/element/handlerRectangles.ts +++ b/src/element/handlerRectangles.ts @@ -131,13 +131,6 @@ export function handlerRectangles( } as typeof handlers; } } - - return { - n: handlers.n, - s: handlers.s, - w: handlers.w, - e: handlers.e, - } as typeof handlers; } return handlers;