From a6ea38db4a8401be2b71ccaa55cc86ed34913379 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Fri, 9 Oct 2015 16:04:19 -0700 Subject: [PATCH] Stop shadow from reappearing when one block replaces another. Issue #193 --- blockly_compressed.js | 8 ++++---- core/connection.js | 5 +++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/blockly_compressed.js b/blockly_compressed.js index 0a17eef03..b185dcb30 100644 --- a/blockly_compressed.js +++ b/blockly_compressed.js @@ -882,10 +882,10 @@ this.foreignObject_=this.textarea_=this.bubble_=null);this.setText(b);this.setBu Blockly.Comment.prototype.getText=function(){return this.textarea_?this.textarea_.value:this.text_};Blockly.Comment.prototype.setText=function(a){this.textarea_?this.textarea_.value=a:this.text_=a};Blockly.Comment.prototype.dispose=function(){this.block_.comment=null;Blockly.Icon.prototype.dispose.call(this)};Blockly.Connection=function(a,b){this.sourceBlock_=a;this.type=b;a.workspace.connectionDBList&&(this.db_=a.workspace.connectionDBList[b],this.dbOpposite_=a.workspace.connectionDBList[Blockly.OPPOSITE_TYPE[b]],this.hidden_=!this.db_)};Blockly.Connection.prototype.targetConnection=null;Blockly.Connection.prototype.check_=null;Blockly.Connection.prototype.shadowDom_=null;Blockly.Connection.prototype.x_=0;Blockly.Connection.prototype.y_=0;Blockly.Connection.prototype.inDB_=!1; Blockly.Connection.prototype.db_=null;Blockly.Connection.prototype.dbOpposite_=null;Blockly.Connection.prototype.hidden_=null;Blockly.Connection.prototype.dispose=function(){if(this.targetConnection)throw"Disconnect connection before disposing of it.";this.inDB_&&this.db_.removeConnection_(this);Blockly.highlightedConnection_==this&&(Blockly.highlightedConnection_=null);Blockly.localConnection_==this&&(Blockly.localConnection_=null);this.dbOpposite_=this.db_=null}; Blockly.Connection.prototype.isSuperior=function(){return this.type==Blockly.INPUT_VALUE||this.type==Blockly.NEXT_STATEMENT}; -Blockly.Connection.prototype.connect=function(a){if(this.sourceBlock_==a.sourceBlock_)throw"Attempted to connect a block to itself.";if(this.sourceBlock_.workspace!==a.sourceBlock_.workspace)throw"Blocks are on different workspaces.";if(Blockly.OPPOSITE_TYPE[this.type]!=a.type)throw"Attempt to connect incompatible types.";if(this.type==Blockly.INPUT_VALUE||this.type==Blockly.OUTPUT_VALUE){if(this.targetConnection)throw"Source connection already connected (value).";if(a.targetConnection){var b=a.targetBlock(); -b.setParent(null);if(b.isShadow())a.setShadowDom(Blockly.Xml.blockToDom_(b)),b.dispose();else{if(!b.outputConnection)throw"Orphan block does not have an output connection.";for(var c=this.sourceBlock_,d;d=Blockly.Connection.singleConnection_(c,b);)if(c=d.targetBlock(),!c||c.isShadow()){b.outputConnection.connect(d);b=null;break}b&&setTimeout(function(){b.outputConnection.bumpAwayFrom_(a)},Blockly.BUMP_DELAY)}}}else{if(this.targetConnection)throw"Source connection already connected (block).";if(a.targetConnection){if(this.type!= -Blockly.PREVIOUS_STATEMENT)throw"Can only do a mid-stack connection with the top of a block.";b=a.targetBlock();b.setParent(null);if(!b.previousConnection)throw"Orphan block does not have a previous connection.";for(c=this.sourceBlock_;c.nextConnection;)if(c.nextConnection.targetConnection)c=c.getNextBlock();else{b.previousConnection.checkType_(c.nextConnection)&&(c.nextConnection.connect(b.previousConnection),b=null);break}b&&setTimeout(function(){b.previousConnection.bumpAwayFrom_(a)},Blockly.BUMP_DELAY)}}this.isSuperior()? -(c=this.sourceBlock_,d=a.sourceBlock_):(c=a.sourceBlock_,d=this.sourceBlock_);this.targetConnection=a;a.targetConnection=this;d.setParent(c);c.rendered&&c.updateDisabled();d.rendered&&d.updateDisabled();c.rendered&&d.rendered&&(this.type==Blockly.NEXT_STATEMENT||this.type==Blockly.PREVIOUS_STATEMENT?d.render():c.render())}; +Blockly.Connection.prototype.connect=function(a){if(this.sourceBlock_==a.sourceBlock_)throw"Attempted to connect a block to itself.";if(this.sourceBlock_.workspace!==a.sourceBlock_.workspace)throw"Blocks are on different workspaces.";if(Blockly.OPPOSITE_TYPE[this.type]!=a.type)throw"Attempt to connect incompatible types.";if(this.type==Blockly.INPUT_VALUE||this.type==Blockly.OUTPUT_VALUE){if(this.targetConnection)throw"Source connection already connected (value).";if(a.targetConnection){var b=a.getShadowDom(); +a.setShadowDom(null);var c=a.targetBlock();c.setParent(null);if(c.isShadow())a.setShadowDom(Blockly.Xml.blockToDom_(c)),c.dispose();else{if(!c.outputConnection)throw"Orphan block does not have an output connection.";for(var d=this.sourceBlock_,e;e=Blockly.Connection.singleConnection_(d,c);)if(d=e.targetBlock(),!d||d.isShadow()){c.outputConnection.connect(e);c=null;break}c&&setTimeout(function(){c.outputConnection.bumpAwayFrom_(a)},Blockly.BUMP_DELAY);a.setShadowDom(b)}}}else{if(this.targetConnection)throw"Source connection already connected (block)."; +if(a.targetConnection){if(this.type!=Blockly.PREVIOUS_STATEMENT)throw"Can only do a mid-stack connection with the top of a block.";c=a.targetBlock();c.setParent(null);if(!c.previousConnection)throw"Orphan block does not have a previous connection.";for(d=this.sourceBlock_;d.nextConnection;)if(d.nextConnection.targetConnection)d=d.getNextBlock();else{c.previousConnection.checkType_(d.nextConnection)&&(d.nextConnection.connect(c.previousConnection),c=null);break}c&&setTimeout(function(){c.previousConnection.bumpAwayFrom_(a)}, +Blockly.BUMP_DELAY)}}this.isSuperior()?(b=this.sourceBlock_,d=a.sourceBlock_):(b=a.sourceBlock_,d=this.sourceBlock_);this.targetConnection=a;a.targetConnection=this;d.setParent(b);b.rendered&&b.updateDisabled();d.rendered&&d.updateDisabled();b.rendered&&d.rendered&&(this.type==Blockly.NEXT_STATEMENT||this.type==Blockly.PREVIOUS_STATEMENT?d.render():b.render())}; Blockly.Connection.singleConnection_=function(a,b){for(var c=!1,d=0;d