|
|
@ -918,6 +918,27 @@ export class App extends React.Component<any, AppState> {
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
event.preventDefault();
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
} else if (event.key === KEYS.ENTER) {
|
|
|
|
|
|
|
|
const selectedElements = getSelectedElements(
|
|
|
|
|
|
|
|
globalSceneState.getAllElements(),
|
|
|
|
|
|
|
|
this.state,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
|
|
|
selectedElements.length === 1 &&
|
|
|
|
|
|
|
|
!isLinearElement(selectedElements[0])
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
const selectedElement = selectedElements[0];
|
|
|
|
|
|
|
|
const x = selectedElement.x + selectedElement.width / 2;
|
|
|
|
|
|
|
|
const y = selectedElement.y + selectedElement.height / 2;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.startTextEditing({
|
|
|
|
|
|
|
|
x: x,
|
|
|
|
|
|
|
|
y: y,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
} else if (
|
|
|
|
} else if (
|
|
|
|
!event.ctrlKey &&
|
|
|
|
!event.ctrlKey &&
|
|
|
|
!event.altKey &&
|
|
|
|
!event.altKey &&
|
|
|
@ -987,24 +1008,19 @@ export class App extends React.Component<any, AppState> {
|
|
|
|
globalSceneState.replaceAllElements(elements);
|
|
|
|
globalSceneState.replaceAllElements(elements);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
private handleCanvasDoubleClick = (
|
|
|
|
private startTextEditing = ({
|
|
|
|
event: React.MouseEvent<HTMLCanvasElement>,
|
|
|
|
x,
|
|
|
|
) => {
|
|
|
|
y,
|
|
|
|
// case: double-clicking with arrow/line tool selected would both create
|
|
|
|
clientX,
|
|
|
|
// text and enter multiElement mode
|
|
|
|
clientY,
|
|
|
|
if (this.state.multiElement) {
|
|
|
|
centerIfPossible = true,
|
|
|
|
return;
|
|
|
|
}: {
|
|
|
|
}
|
|
|
|
x: number;
|
|
|
|
|
|
|
|
y: number;
|
|
|
|
resetCursor();
|
|
|
|
clientX?: number;
|
|
|
|
|
|
|
|
clientY?: number;
|
|
|
|
const { x, y } = viewportCoordsToSceneCoords(
|
|
|
|
centerIfPossible?: boolean;
|
|
|
|
event,
|
|
|
|
}) => {
|
|
|
|
this.state,
|
|
|
|
|
|
|
|
this.canvas,
|
|
|
|
|
|
|
|
window.devicePixelRatio,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const elementAtPosition = getElementAtPosition(
|
|
|
|
const elementAtPosition = getElementAtPosition(
|
|
|
|
globalSceneState.getAllElements(),
|
|
|
|
globalSceneState.getAllElements(),
|
|
|
|
this.state,
|
|
|
|
this.state,
|
|
|
@ -1031,8 +1047,8 @@ export class App extends React.Component<any, AppState> {
|
|
|
|
|
|
|
|
|
|
|
|
this.setState({ editingElement: element });
|
|
|
|
this.setState({ editingElement: element });
|
|
|
|
|
|
|
|
|
|
|
|
let textX = event.clientX;
|
|
|
|
let textX = clientX || x;
|
|
|
|
let textY = event.clientY;
|
|
|
|
let textY = clientY || y;
|
|
|
|
|
|
|
|
|
|
|
|
if (elementAtPosition && isTextElement(elementAtPosition)) {
|
|
|
|
if (elementAtPosition && isTextElement(elementAtPosition)) {
|
|
|
|
globalSceneState.replaceAllElements(
|
|
|
|
globalSceneState.replaceAllElements(
|
|
|
@ -1062,7 +1078,7 @@ export class App extends React.Component<any, AppState> {
|
|
|
|
x: centerElementX,
|
|
|
|
x: centerElementX,
|
|
|
|
y: centerElementY,
|
|
|
|
y: centerElementY,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else if (!event.altKey) {
|
|
|
|
} else if (centerIfPossible) {
|
|
|
|
const snappedToCenterPosition = this.getTextWysiwygSnappedToCenterPosition(
|
|
|
|
const snappedToCenterPosition = this.getTextWysiwygSnappedToCenterPosition(
|
|
|
|
x,
|
|
|
|
x,
|
|
|
|
y,
|
|
|
|
y,
|
|
|
@ -1119,6 +1135,33 @@ export class App extends React.Component<any, AppState> {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private handleCanvasDoubleClick = (
|
|
|
|
|
|
|
|
event: React.MouseEvent<HTMLCanvasElement>,
|
|
|
|
|
|
|
|
) => {
|
|
|
|
|
|
|
|
// case: double-clicking with arrow/line tool selected would both create
|
|
|
|
|
|
|
|
// text and enter multiElement mode
|
|
|
|
|
|
|
|
if (this.state.multiElement) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
resetCursor();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const { x, y } = viewportCoordsToSceneCoords(
|
|
|
|
|
|
|
|
event,
|
|
|
|
|
|
|
|
this.state,
|
|
|
|
|
|
|
|
this.canvas,
|
|
|
|
|
|
|
|
window.devicePixelRatio,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.startTextEditing({
|
|
|
|
|
|
|
|
x: x,
|
|
|
|
|
|
|
|
y: y,
|
|
|
|
|
|
|
|
clientX: event.clientX,
|
|
|
|
|
|
|
|
clientY: event.clientY,
|
|
|
|
|
|
|
|
centerIfPossible: !event.altKey,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
private handleCanvasPointerMove = (
|
|
|
|
private handleCanvasPointerMove = (
|
|
|
|
event: React.PointerEvent<HTMLCanvasElement>,
|
|
|
|
event: React.PointerEvent<HTMLCanvasElement>,
|
|
|
|
) => {
|
|
|
|
) => {
|
|
|
|