Fix missing mouseup (#144)

This commit is contained in:
Christopher Chedeau 2020-01-04 18:36:49 -08:00 committed by GitHub
parent 9e5c5daf64
commit 85fe9f85fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -832,6 +832,8 @@ const ELEMENT_TRANSLATE_AMOUNT = 1;
let lastCanvasWidth = -1;
let lastCanvasHeight = -1;
let lastMouseUp: ((e: any) => void) | null = null;
class App extends React.Component<{}, AppState> {
public componentDidMount() {
document.addEventListener("keydown", this.onKeyDown, false);
@ -1157,6 +1159,12 @@ class App extends React.Component<{}, AppState> {
}
}}
onMouseDown={e => {
if (lastMouseUp !== null) {
// Unfortunately, sometimes we don't get a mouseup after a mousedown,
// this can happen when a contextual menu or alert is triggered. In order to avoid
// being in a weird state, we clean up on the next mousedown
lastMouseUp(e);
}
// only handle left mouse button
if (e.button !== 0) return;
// fixes mousemove causing selection of UI texts #32
@ -1398,6 +1406,7 @@ class App extends React.Component<{}, AppState> {
const onMouseUp = (e: MouseEvent) => {
const { draggingElement, elementType } = this.state;
lastMouseUp = null;
window.removeEventListener("mousemove", onMouseMove);
window.removeEventListener("mouseup", onMouseUp);
@ -1426,6 +1435,8 @@ class App extends React.Component<{}, AppState> {
this.forceUpdate();
};
lastMouseUp = onMouseUp;
window.addEventListener("mousemove", onMouseMove);
window.addEventListener("mouseup", onMouseUp);