From 85fe9f85fb696013a2cc04d9735b7097f565a71c Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Sat, 4 Jan 2020 18:36:49 -0800 Subject: [PATCH] Fix missing mouseup (#144) --- src/index.tsx | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/index.tsx b/src/index.tsx index 9930e264..e2d2243c 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -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);