Disable resize for text, arrow and multiple selection

This commit is contained in:
Paulo Menezes 2020-01-04 15:36:29 -03:00
parent bf883a604a
commit 5102955630

View file

@ -176,6 +176,8 @@ function resizeTest(
y: number,
sceneState: SceneState
): string | false {
if (element.type === "text" || element.type === "arrow") return false;
const x1 = getElementAbsoluteX1(element);
const x2 = getElementAbsoluteX2(element);
const y1 = getElementAbsoluteY1(element);
@ -353,6 +355,8 @@ function renderScene(
}
context.fillStyle = fillStyle;
const selectedIndices = getSelectedIndices();
elements.forEach(element => {
element.draw(rc, context, sceneState);
if (element.isSelected) {
@ -372,6 +376,11 @@ function renderScene(
);
context.setLineDash(lineDash);
if (
element.type !== "text" &&
element.type !== "arrow" &&
selectedIndices.length === 1
) {
const handlers = handlerRectangles(
elementX1,
elementX2,
@ -383,6 +392,7 @@ function renderScene(
context.strokeRect(handler[0], handler[1], handler[2], handler[3]);
});
}
}
});
const scrollBars = getScrollbars(
@ -1150,9 +1160,9 @@ class App extends React.Component<{}, AppState> {
});
document.documentElement.style.cursor = `${resizeHandle}-resize`;
isResizingElements = true;
}
} else {
let hitElement = null;
// We need to to hit testing from front (end of the array) to back (beginning of the array)
for (let i = elements.length - 1; i >= 0; --i) {
if (hitTest(elements[i], x, y)) {
@ -1179,7 +1189,6 @@ class App extends React.Component<{}, AppState> {
clearSelection();
}
if (!isResizingElements) {
isDraggingElements = someElementIsSelected();
if (isDraggingElements) {
@ -1236,7 +1245,7 @@ class App extends React.Component<{}, AppState> {
if (isResizingElements && this.state.resizingElement) {
const el = this.state.resizingElement;
const selectedElements = elements.filter(el => el.isSelected);
if (selectedElements.length) {
if (selectedElements.length === 1) {
const x = e.clientX - target.offsetLeft - this.state.scrollX;
const y = e.clientY - target.offsetTop - this.state.scrollY;
selectedElements.forEach(element => {