Bug 1451683 - Avoid reacting to mousedown twice in a row when starting to drag the splitter; r=miker draft
authorPatrick Brosset <pbrosset@mozilla.com>
Fri, 04 May 2018 17:12:45 +0200
changeset 791518 99ed544f4715e3aa416ace9f9816b567ba640ec9
parent 791409 8994f35fe5fc89f4e8f4e09579a6962f8a4a3e65
push id108833
push userbmo:pbrosset@mozilla.com
push dateFri, 04 May 2018 15:13:36 +0000
reviewersmiker
bugs1451683
milestone61.0a1
Bug 1451683 - Avoid reacting to mousedown twice in a row when starting to drag the splitter; r=miker MozReview-Commit-ID: ClTdZ03tB0U
devtools/client/shared/components/splitter/Draggable.js
--- a/devtools/client/shared/components/splitter/Draggable.js
+++ b/devtools/client/shared/components/splitter/Draggable.js
@@ -23,31 +23,45 @@ class Draggable extends Component {
   constructor(props) {
     super(props);
     this.startDragging = this.startDragging.bind(this);
     this.onMove = this.onMove.bind(this);
     this.onUp = this.onUp.bind(this);
   }
 
   startDragging(ev) {
+    if (this.isDragging) {
+      return;
+    }
+    this.isDragging = true;
+
     ev.preventDefault();
     const doc = ReactDOM.findDOMNode(this).ownerDocument;
     doc.addEventListener("mousemove", this.onMove);
     doc.addEventListener("mouseup", this.onUp);
     this.props.onStart && this.props.onStart();
   }
 
   onMove(ev) {
+    if (!this.isDragging) {
+      return;
+    }
+
     ev.preventDefault();
     // Use viewport coordinates so, moving mouse over iframes
     // doesn't mangle (relative) coordinates.
     this.props.onMove(ev.clientX, ev.clientY);
   }
 
   onUp(ev) {
+    if (!this.isDragging) {
+      return;
+    }
+    this.isDragging = false;
+
     ev.preventDefault();
     const doc = ReactDOM.findDOMNode(this).ownerDocument;
     doc.removeEventListener("mousemove", this.onMove);
     doc.removeEventListener("mouseup", this.onUp);
     this.props.onStop && this.props.onStop();
   }
 
   render() {