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