From 0027d9294a1dea2b544c924e444868153febd9e0 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Mon, 1 Feb 2016 16:13:05 -0800 Subject: [PATCH] Double speed of workspace drag. --- core/block.js | 15 +++------------ core/block_svg.js | 10 +++------- core/scrollbar.js | 29 +++++++++++++++++++++++++++-- 3 files changed, 33 insertions(+), 21 deletions(-) diff --git a/core/block.js b/core/block.js index ba3831c5d..9c74eb446 100644 --- a/core/block.js +++ b/core/block.js @@ -160,10 +160,9 @@ Blockly.Block.prototype.colour_ = '#000000'; * @param {boolean} healStack If true, then try to heal any gap by connecting * the next statement with the previous statement. Otherwise, dispose of * all children of this block. - * @param {boolean} animate If true, show a disposal animation and sound. */ -Blockly.Block.prototype.dispose = function(healStack, animate) { - this.unplug(healStack, false); +Blockly.Block.prototype.dispose = function(healStack) { + this.unplug(healStack); if (Blockly.Events.isEnabled() && !this.isShadow()) { Blockly.Events.fire(new Blockly.Events.Delete(this)); } @@ -212,10 +211,8 @@ Blockly.Block.prototype.dispose = function(healStack, animate) { * Unplug this block from its superior block. If this block is a statement, * optionally reconnect the block underneath with the block on top. * @param {boolean} healStack Disconnect child statement and reconnect stack. - * @param {boolean} bump Move the unplugged block sideways a short distance. */ -Blockly.Block.prototype.unplug = function(healStack, bump) { - bump = bump && !!this.getParent(); +Blockly.Block.prototype.unplug = function(healStack) { if (this.outputConnection) { if (this.outputConnection.targetConnection) { // Disconnect from any superior block. @@ -240,12 +237,6 @@ Blockly.Block.prototype.unplug = function(healStack, bump) { } } } - if (bump) { - // Bump the block sideways. - var dx = Blockly.SNAP_RADIUS * (this.RTL ? -1 : 1); - var dy = Blockly.SNAP_RADIUS * 2; - this.moveBy(dx, dy); - } }; /** diff --git a/core/block_svg.js b/core/block_svg.js index 940568c85..dfe4da466 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -499,12 +499,8 @@ Blockly.BlockSvg.prototype.onMouseUp_ = function(e) { if (this.rendered) { // Trigger a connection animation. // Determine which connection is inferior (lower in the source stack). - var inferiorConnection; - if (Blockly.localConnection_.isSuperior()) { - inferiorConnection = Blockly.highlightedConnection_; - } else { - inferiorConnection = Blockly.localConnection_; - } + var inferiorConnection = Blockly.localConnection_.isSuperior() ? + Blockly.highlightedConnection_ : Blockly.localConnection_; inferiorConnection.sourceBlock_.connectionUiEffect(); } if (this.workspace.trashcan) { @@ -1105,7 +1101,7 @@ Blockly.BlockSvg.prototype.dispose = function(healStack, animate) { } if (animate && this.rendered) { - this.unplug(healStack, false); + this.unplug(healStack); this.disposeUiEffect(); } // Stop rerendering. diff --git a/core/scrollbar.js b/core/scrollbar.js index e872900f0..e83a42fbf 100644 --- a/core/scrollbar.js +++ b/core/scrollbar.js @@ -136,8 +136,33 @@ Blockly.ScrollbarPair.prototype.resize = function() { * @param {number} y Vertical scroll value. */ Blockly.ScrollbarPair.prototype.set = function(x, y) { - this.hScroll.set(x); - this.vScroll.set(y); + // This function is equivalent to: + // this.hScroll.set(x); + // this.vScroll.set(y); + // However, that calls setMetrics twice. Combining them speeds up rendering. + var xyRatio = {}; + + var knobValue = x * this.hScroll.ratio_; + this.hScroll.svgKnob_.setAttribute('x', knobValue); + var barLength = parseFloat(this.hScroll.svgBackground_.getAttribute('width')); + var ratio = knobValue / barLength; + if (isNaN(ratio)) { + ratio = 0; + } + xyRatio.x = ratio; + + var knobValue = y * this.vScroll.ratio_; + this.vScroll.svgKnob_.setAttribute('y', knobValue); + var barLength = + parseFloat(this.vScroll.svgBackground_.getAttribute('height')); + var ratio = knobValue / barLength; + if (isNaN(ratio)) { + ratio = 0; + } + xyRatio.y = ratio; + + this.workspace_.setMetrics(xyRatio); + }; // --------------------------------------------------------------------