From d2c61d57357406490cde305725518a5c30b96a65 Mon Sep 17 00:00:00 2001 From: Monica Kozbial <6621618+moniika@users.noreply.github.com> Date: Wed, 9 Jun 2021 19:20:47 -0700 Subject: [PATCH] Prevent uncessary add/remove class calls on cursor during drag (#4885) --- core/block_dragger.js | 9 ++++++--- core/bubble_dragger.js | 14 +++++++------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/core/block_dragger.js b/core/block_dragger.js index c9c477430..8dfac6542 100644 --- a/core/block_dragger.js +++ b/core/block_dragger.js @@ -217,9 +217,12 @@ Blockly.BlockDragger.prototype.dragBlock = function(e, currentDragDeltaXY) { } this.draggedConnectionManager_.update(delta, this.dragTarget_); - this.wouldDeleteBlock_ = this.draggedConnectionManager_.wouldDeleteBlock(); - - this.updateCursorDuringBlockDrag_(); + var wouldDeleteBlock = this.draggedConnectionManager_.wouldDeleteBlock(); + if (wouldDeleteBlock != this.wouldDeleteBlock_) { + // Prevent unnecessary add/remove class calls. + this.updateCursorDuringBlockDrag_(); + } + this.wouldDeleteBlock_ = wouldDeleteBlock; }; /** diff --git a/core/bubble_dragger.js b/core/bubble_dragger.js index 38c339158..2112eb3ab 100644 --- a/core/bubble_dragger.js +++ b/core/bubble_dragger.js @@ -140,9 +140,13 @@ Blockly.BubbleDragger.prototype.dragBubble = function(e, currentDragDeltaXY) { oldDragTarget && oldDragTarget.onDragExit(); this.dragTarget_ && this.dragTarget_.onDragEnter(); } - this.wouldDeleteBubble_ = this.shouldDelete_(this.dragTarget_); - this.updateCursorDuringBubbleDrag_(); + var wouldDeleteBubble = this.shouldDelete_(this.dragTarget_); + if (wouldDeleteBubble != this.wouldDeleteBubble_) { + // Prevent unnecessary add/remove class calls. + this.updateCursorDuringBubbleDrag_(); + } + this.wouldDeleteBubble_ = wouldDeleteBubble; }; /** @@ -177,11 +181,7 @@ Blockly.BubbleDragger.prototype.shouldDelete_ = function(dragTarget) { * @private */ Blockly.BubbleDragger.prototype.updateCursorDuringBubbleDrag_ = function() { - if (this.wouldDeleteBubble_) { - this.draggingBubble_.setDeleteStyle(true); - } else { - this.draggingBubble_.setDeleteStyle(false); - } + this.draggingBubble_.setDeleteStyle(this.wouldDeleteBubble_); }; /**