Support negative resize for multiple points line/arrow (#1237)
* Support negative resize for multiple points line * prettier * Fix an issue with width or height becoming zero
This commit is contained in:
parent
d5899f6ca0
commit
b1ed5b4cdc
@ -144,7 +144,7 @@ export function resizeElements(
|
|||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
...adjustXYWithRotation("nw", element, deltaX, dY, angle),
|
...adjustXYWithRotation("nw", element, deltaX, dY, angle),
|
||||||
...(isLinearElement(element) && width >= 0 && height >= 0
|
...(isLinearElement(element) && width !== 0 && height !== 0
|
||||||
? {
|
? {
|
||||||
points: rescalePoints(
|
points: rescalePoints(
|
||||||
0,
|
0,
|
||||||
@ -176,7 +176,7 @@ export function resizeElements(
|
|||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
...adjustXYWithRotation("ne", element, deltaX, dY, angle),
|
...adjustXYWithRotation("ne", element, deltaX, dY, angle),
|
||||||
...(isLinearElement(element) && width >= 0 && height >= 0
|
...(isLinearElement(element) && width !== 0 && height !== 0
|
||||||
? {
|
? {
|
||||||
points: rescalePoints(
|
points: rescalePoints(
|
||||||
0,
|
0,
|
||||||
@ -208,7 +208,7 @@ export function resizeElements(
|
|||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
...adjustXYWithRotation("sw", element, deltaX, dY, angle),
|
...adjustXYWithRotation("sw", element, deltaX, dY, angle),
|
||||||
...(isLinearElement(element) && width >= 0 && height >= 0
|
...(isLinearElement(element) && width !== 0 && height !== 0
|
||||||
? {
|
? {
|
||||||
points: rescalePoints(
|
points: rescalePoints(
|
||||||
0,
|
0,
|
||||||
@ -240,7 +240,7 @@ export function resizeElements(
|
|||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
...adjustXYWithRotation("se", element, deltaX, dY, angle),
|
...adjustXYWithRotation("se", element, deltaX, dY, angle),
|
||||||
...(isLinearElement(element) && width >= 0 && height >= 0
|
...(isLinearElement(element) && width !== 0 && height !== 0
|
||||||
? {
|
? {
|
||||||
points: rescalePoints(
|
points: rescalePoints(
|
||||||
0,
|
0,
|
||||||
@ -255,12 +255,7 @@ export function resizeElements(
|
|||||||
case "n": {
|
case "n": {
|
||||||
const height = element.height - deltaY;
|
const height = element.height - deltaY;
|
||||||
|
|
||||||
if (isLinearElement(element)) {
|
if (isLinearElement(element) && height !== 0) {
|
||||||
if (element.points.length > 2 && height <= 0) {
|
|
||||||
// Someday we should implement logic to flip the shape.
|
|
||||||
// But for now, just stop.
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
mutateElement(element, {
|
mutateElement(element, {
|
||||||
height,
|
height,
|
||||||
...adjustXYWithRotation("n", element, 0, deltaY, angle),
|
...adjustXYWithRotation("n", element, 0, deltaY, angle),
|
||||||
@ -278,13 +273,7 @@ export function resizeElements(
|
|||||||
case "w": {
|
case "w": {
|
||||||
const width = element.width - deltaX;
|
const width = element.width - deltaX;
|
||||||
|
|
||||||
if (isLinearElement(element)) {
|
if (isLinearElement(element) && width !== 0) {
|
||||||
if (element.points.length > 2 && width <= 0) {
|
|
||||||
// Someday we should implement logic to flip the shape.
|
|
||||||
// But for now, just stop.
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
mutateElement(element, {
|
mutateElement(element, {
|
||||||
width,
|
width,
|
||||||
...adjustXYWithRotation("w", element, deltaX, 0, angle),
|
...adjustXYWithRotation("w", element, deltaX, 0, angle),
|
||||||
@ -301,12 +290,7 @@ export function resizeElements(
|
|||||||
case "s": {
|
case "s": {
|
||||||
const height = element.height + deltaY;
|
const height = element.height + deltaY;
|
||||||
|
|
||||||
if (isLinearElement(element)) {
|
if (isLinearElement(element) && height !== 0) {
|
||||||
if (element.points.length > 2 && height <= 0) {
|
|
||||||
// Someday we should implement logic to flip the shape.
|
|
||||||
// But for now, just stop.
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
mutateElement(element, {
|
mutateElement(element, {
|
||||||
height,
|
height,
|
||||||
...adjustXYWithRotation("s", element, 0, deltaY, angle),
|
...adjustXYWithRotation("s", element, 0, deltaY, angle),
|
||||||
@ -323,12 +307,7 @@ export function resizeElements(
|
|||||||
case "e": {
|
case "e": {
|
||||||
const width = element.width + deltaX;
|
const width = element.width + deltaX;
|
||||||
|
|
||||||
if (isLinearElement(element)) {
|
if (isLinearElement(element) && width !== 0) {
|
||||||
if (element.points.length > 2 && width <= 0) {
|
|
||||||
// Someday we should implement logic to flip the shape.
|
|
||||||
// But for now, just stop.
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
mutateElement(element, {
|
mutateElement(element, {
|
||||||
width,
|
width,
|
||||||
...adjustXYWithRotation("e", element, deltaX, 0, angle),
|
...adjustXYWithRotation("e", element, deltaX, 0, angle),
|
||||||
|
@ -10,7 +10,6 @@ import {
|
|||||||
handlerRectangles,
|
handlerRectangles,
|
||||||
} from "./handlerRectangles";
|
} from "./handlerRectangles";
|
||||||
import { AppState } from "../types";
|
import { AppState } from "../types";
|
||||||
import { isLinearElement } from "./typeChecks";
|
|
||||||
|
|
||||||
type HandlerRectanglesRet = keyof ReturnType<typeof handlerRectangles>;
|
type HandlerRectanglesRet = keyof ReturnType<typeof handlerRectangles>;
|
||||||
|
|
||||||
@ -155,7 +154,7 @@ export function normalizeResizeHandle(
|
|||||||
element: ExcalidrawElement,
|
element: ExcalidrawElement,
|
||||||
resizeHandle: HandlerRectanglesRet,
|
resizeHandle: HandlerRectanglesRet,
|
||||||
): HandlerRectanglesRet {
|
): HandlerRectanglesRet {
|
||||||
if ((element.width >= 0 && element.height >= 0) || isLinearElement(element)) {
|
if (element.width >= 0 && element.height >= 0) {
|
||||||
return resizeHandle;
|
return resizeHandle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,11 +81,7 @@ export function resizePerfectLineForNWHandler(
|
|||||||
export function normalizeDimensions(
|
export function normalizeDimensions(
|
||||||
element: ExcalidrawElement | null,
|
element: ExcalidrawElement | null,
|
||||||
): element is ExcalidrawElement {
|
): element is ExcalidrawElement {
|
||||||
if (
|
if (!element || (element.width >= 0 && element.height >= 0)) {
|
||||||
!element ||
|
|
||||||
(element.width >= 0 && element.height >= 0) ||
|
|
||||||
isLinearElement(element)
|
|
||||||
) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user