From 27710d2f79954e3e38a49a679b50e05212a9911f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20M=C3=B6nig?= Date: Sat, 22 Jan 2022 00:46:23 +0100 Subject: [PATCH] support dragging blocks out from variable watchers --- HISTORY.md | 3 ++- src/objects.js | 24 +++++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 0c54fa24..70491c42 100755 --- a/HISTORY.md +++ b/HISTORY.md @@ -3,7 +3,7 @@ ## in development: * **New Features:** - * support dragging blocks out from result bubbles and speech balloons + * support dragging blocks out from result bubbles, speech balloons and variable watchers * **Notable Changes:** * **Notable Fixes:** * fixed layout for scrolling custom categories, thanks, Eckart, for the bug report! @@ -13,6 +13,7 @@ ### 2022-01-22 * blocks: support dragging blocks out from result bubbles * objects: support dragging blocks out from speech balloons +* objects: support dragging blocks out from variable watchers ### 2022-01-21 * new dev version diff --git a/src/objects.js b/src/objects.js index b02775fa..e26bc803 100644 --- a/src/objects.js +++ b/src/objects.js @@ -10052,7 +10052,7 @@ SpriteBubbleMorph.prototype.dataAsMorph = function (data) { contents.bounds.setHeight(img.height); contents.cachedImage = img; - // support blocks to be dragged out of result bubbles: + // support blocks to be dragged out of speech balloons: contents.isDraggable = true; contents.selectForEdit = function () { @@ -11383,6 +11383,7 @@ CellMorph.prototype.createContents = function () { // re-build my contents var txt, img, + myself = this, fontSize = SyntaxElementMorph.prototype.fontSize, isSameList = this.contentsMorph instanceof ListWatcherMorph && (this.contentsMorph.list === this.contents), @@ -11451,6 +11452,27 @@ CellMorph.prototype.createContents = function () { this.contentsMorph.bounds.setWidth(img.width); this.contentsMorph.bounds.setHeight(img.height); this.contentsMorph.cachedImage = img; + + // support blocks to be dragged out of watchers: + this.contentsMorph.isDraggable = true; + + this.contentsMorph.selectForEdit = function () { + var script = myself.contents.toBlock(), + prepare = script.prepareToBeGrabbed, + ide = this.parentThatIsA(IDE_Morph); + + script.prepareToBeGrabbed = function (hand) { + prepare.call(this, hand); + hand.grabOrigin = { + origin: ide.palette, + position: ide.palette.center() + }; + this.prepareToBeGrabbed = prepare; + }; + + script.setPosition(this.position()); + return script; + }; } else if (this.contents instanceof Costume) { img = this.contents.thumbnail(new Point(40, 40)); this.contentsMorph = new Morph();