summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjmoenig <jens@moenig.org>2013-08-02 12:05:34 +0200
committerjmoenig <jens@moenig.org>2013-08-02 12:05:34 +0200
commitf9c8fb04e0ded8e0a650b768ef87f7904c51233e (patch)
tree5ef052fdd3514a82424b36b3cdb8740ca4d99571
parent3d08b59fe0f04d0c16437a5c748603bf28398e23 (diff)
downloadsnap-byow-f9c8fb04e0ded8e0a650b768ef87f7904c51233e.tar.gz
snap-byow-f9c8fb04e0ded8e0a650b768ef87f7904c51233e.zip
Undrop Commands feature
first iteration
-rw-r--r--blocks.js53
-rwxr-xr-xhistory.txt1
2 files changed, 44 insertions, 10 deletions
diff --git a/blocks.js b/blocks.js
index 9dfe68c..036161d 100644
--- a/blocks.js
+++ b/blocks.js
@@ -3158,6 +3158,7 @@ CommandBlockMorph.prototype.snap = function () {
affected;
scripts.clearDropHistory();
+ scripts.lastDroppedBlock = this;
if (target === null) {
this.startLayout();
@@ -3166,12 +3167,17 @@ CommandBlockMorph.prototype.snap = function () {
CommandBlockMorph.uber.snap.call(this); // align stuck comments
return;
}
+
+ scripts.lastDropTarget = target;
+
this.startLayout();
if (target.loc === 'bottom') {
if (target.type === 'slot') {
this.removeHighlight();
+ scripts.lastNextBlock = target.element.nestedBlock();
target.element.nestedBlock(this);
} else {
+ scripts.lastNextBlock = target.element.nextBlock();
target.element.nextBlock(this);
}
if (this.isStop()) {
@@ -4457,6 +4463,7 @@ ScriptsMorph.prototype.init = function (owner) {
this.lastReplacedInput = null;
this.lastDropTarget = null;
this.lastPreservedBlocks = null;
+ this.lastNextBlock = null;
ScriptsMorph.uber.init.call(this);
this.setColor(new Color(70, 70, 70));
@@ -4864,16 +4871,41 @@ ScriptsMorph.prototype.addComment = function () {
ScriptsMorph.prototype.undrop = function () {
if (!this.lastDroppedBlock) {return; }
- if (this.lastDropTarget) {
- this.lastDropTarget.replaceInput(
- this.lastDroppedBlock,
- this.lastReplacedInput
- );
- this.lastDropTarget.fixBlockColor(null, true);
- if (this.lastPreservedBlocks) {
- this.lastPreservedBlocks.forEach(function (morph) {
- morph.destroy();
- });
+ if (this.lastDroppedBlock instanceof CommandBlockMorph) {
+ if (this.lastNextBlock) {
+ this.add(this.lastNextBlock);
+ }
+ if (this.lastDropTarget) {
+ if (this.lastDropTarget.loc === 'bottom') {
+ if (this.lastDropTarget.type === 'slot') {
+ if (this.lastNextBlock) {
+ this.lastDropTarget.element.nestedBlock(
+ this.lastNextBlock
+ );
+ }
+ } else { // 'block'
+ if (this.lastNextBlock) {
+ this.lastDropTarget.element.nextBlock(
+ this.lastNextBlock
+ );
+ }
+ }
+ } else if (this.lastDropTarget.loc === 'top') {
+ this.add(this.lastDropTarget.element);
+ }
+ }
+ } else { // ReporterBlockMorph
+ if (this.lastDropTarget) {
+ this.lastDropTarget.replaceInput(
+ this.lastDroppedBlock,
+ this.lastReplacedInput
+ );
+ this.lastDropTarget.fixBlockColor(null, true);
+ if (this.lastPreservedBlocks) {
+ this.lastPreservedBlocks.forEach(function (morph) {
+ morph.destroy();
+ });
+ }
}
}
this.lastDroppedBlock.pickUp(this.world());
@@ -4886,6 +4918,7 @@ ScriptsMorph.prototype.clearDropHistory = function () {
this.lastReplacedInput = null;
this.lastDropTarget = null;
this.lastPreservedBlocks = null;
+ this.lastNextBlock = null;
};
// ScriptsMorph blocks layout fix
diff --git a/history.txt b/history.txt
index e28f7a0..7b82d31 100755
--- a/history.txt
+++ b/history.txt
@@ -1844,3 +1844,4 @@ ______
------
* Blocks: Undrop Reporters feature tweaks
* Blocks: Undrop Comments feature
+* Blocks: Undrop Commands feature