mirror of
https://github.com/google/blockly.git
synced 2026-06-16 16:15:14 +02:00
Stop shadow from reappearing when one block replaces another. Issue #193
This commit is contained in:
@@ -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<a.inputList.length;d++){var e=a.inputList[d].connection;if(e&&e.type==Blockly.INPUT_VALUE&&b.outputConnection.checkType_(e)){if(c)return null;c=e}}return c};
|
||||
Blockly.Connection.prototype.disconnect=function(){var a=this.targetConnection;if(!a)throw"Source connection not connected.";if(a.targetConnection!=this)throw"Target connection not connected to source connection.";this.targetConnection=a.targetConnection=null;var b,c;this.isSuperior()?(b=this.sourceBlock_,c=a.sourceBlock_,a=this):(b=a.sourceBlock_,c=this.sourceBlock_);var d=a.getShadowDom();if(b.workspace&&!c.isShadow()&&d){d=Blockly.Xml.domToBlock(b.workspace,d);if(d.outputConnection)a.connect(d.outputConnection);
|
||||
else if(d.previousConnection)a.connect(d.previousConnection);else throw"Child block does not have output or previous statement.";d.initSvg();d.render(!1)}b.rendered&&b.render();c.rendered&&(c.updateDisabled(),c.render())};Blockly.Connection.prototype.targetBlock=function(){return this.targetConnection?this.targetConnection.sourceBlock_:null};
|
||||
|
||||
@@ -161,6 +161,9 @@ Blockly.Connection.prototype.connect = function(otherConnection) {
|
||||
// Can't make a value connection if male block is already connected.
|
||||
throw 'Source connection already connected (value).';
|
||||
} else if (otherConnection.targetConnection) {
|
||||
// Record and disable the shadow so that it does not respawn here.
|
||||
var shadowDom = otherConnection.getShadowDom();
|
||||
otherConnection.setShadowDom(null);
|
||||
// If female block is already connected, disconnect and bump the male.
|
||||
var orphanBlock = otherConnection.targetBlock();
|
||||
orphanBlock.setParent(null);
|
||||
@@ -191,6 +194,8 @@ Blockly.Connection.prototype.connect = function(otherConnection) {
|
||||
orphanBlock.outputConnection.bumpAwayFrom_(otherConnection);
|
||||
}, Blockly.BUMP_DELAY);
|
||||
}
|
||||
// Restore the shadow.
|
||||
otherConnection.setShadowDom(shadowDom);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user