diff --git a/src/blocks/Block.as b/src/blocks/Block.as index 4a83dda..44f00ca 100644 --- a/src/blocks/Block.as +++ b/src/blocks/Block.as @@ -43,7 +43,7 @@ import flash.display.*; import translation.Translator; import util.*; import uiwidgets.*; - import scratch.ScratchStage; + import scratch.*; public class Block extends Sprite { @@ -824,6 +824,22 @@ public class Block extends Sprite { Scratch.app.runtime.checkForGraphicEffects(); } + public function attachedCommentsIn(scriptsPane:ScriptsPane):Array { + var allBlocks:Array = []; + allBlocksDo(function (b:Block):void { + allBlocks.push(b); + }); + var result:Array = [] + if (!scriptsPane) return result; + for (var i:int = 0; i < scriptsPane.numChildren; i++) { + var c:ScratchComment = scriptsPane.getChildAt(i) as ScratchComment; + if (c && c.blockRef && allBlocks.indexOf(c.blockRef) != -1) { + result.push(c); + } + } + return result; + } + public function addComment():void { var scriptsPane:ScriptsPane = topBlock().parent as ScriptsPane; if (scriptsPane) scriptsPane.addComment(this); diff --git a/src/scratch/ScratchRuntime.as b/src/scratch/ScratchRuntime.as index 064be48..34372c9 100644 --- a/src/scratch/ScratchRuntime.as +++ b/src/scratch/ScratchRuntime.as @@ -989,6 +989,16 @@ public class ScratchRuntime { public function clearLastDelete():void { lastDelete = null } public function recordForUndelete(obj:*, x:int, y:int, index:int, owner:* = null):void { + if (obj is Block) { + var comments:Array = (obj as Block).attachedCommentsIn(app.scriptsPane); + if (comments.length) { + for each (var c:ScratchComment in comments) { + c.parent.removeChild(c); + } + app.scriptsPane.fixCommentLayout(); + obj = [obj, comments]; + } + } lastDelete = [obj, x, y, index, owner]; } @@ -1014,13 +1024,20 @@ public class ScratchRuntime { app.addNewSprite(obj); obj.setScratchXY(x, y); app.selectSprite(obj); - } else if ((obj is Block) || (obj is ScratchComment)) { + } else if ((obj is Array) || (obj is Block) || (obj is ScratchComment)) { app.selectSprite(prevOwner); app.setTab('scripts'); - obj.x = app.scriptsPane.padding; - obj.y = app.scriptsPane.padding; - if (obj is Block) obj.cacheAsBitmap = true; - app.scriptsPane.addChild(obj); + var b:DisplayObject = obj is Array ? obj[0] : obj; + b.x = app.scriptsPane.padding; + b.y = app.scriptsPane.padding; + if (b is Block) b.cacheAsBitmap = true; + app.scriptsPane.addChild(b); + if (obj is Array) { + for each (var c:ScratchComment in obj[1]) { + app.scriptsPane.addChild(c); + } + app.scriptsPane.fixCommentLayout(); + } } }