diff --git a/blocks.js b/blocks.js index 50b8adc1..6ed31f01 100644 --- a/blocks.js +++ b/blocks.js @@ -150,7 +150,7 @@ CustomCommandBlockMorph*/ // Global stuff //////////////////////////////////////////////////////// -modules.blocks = '2017-June-20'; +modules.blocks = '2017-June-22'; var SyntaxElementMorph; var BlockMorph; @@ -3736,6 +3736,23 @@ BlockMorph.prototype.mouseClickLeft = function () { } }; +BlockMorph.prototype.selectForEdit = function () { + var rcvr = this.scriptTarget(), + selected; + if (rcvr.inheritsAttribute('scripts')) { + // copy on write: + this.selectionID = true; + rcvr.shadowAttribute('scripts'); + selected = detect(rcvr.scripts.allChildren(), function (m) { + return m.selectionID; + }); + delete this.selectionID; + delete selected.selectionID; + return selected; + } + return this; +}; + BlockMorph.prototype.focus = function () { var scripts = this.parentThatIsA(ScriptsMorph), world = this.world(), @@ -6602,6 +6619,17 @@ ScriptsMorph.prototype.mouseClickLeft = function (pos) { if (this.focus) {this.focus.stopEditing(); } }; +ScriptsMorph.prototype.selectForEdit = function () { + var rcvr = this.scriptTarget(); + if (rcvr.inheritsAttribute('scripts')) { + // copy on write: + this.feedbackMorph.destroy(); + rcvr.shadowAttribute('scripts'); + return rcvr.scripts; + } + return this; +}; + // ScriptsMorph keyboard support ScriptsMorph.prototype.edit = function (pos) { @@ -12805,6 +12833,9 @@ CommentMorph.prototype.fullCopy = function () { var cpy = new CommentMorph(this.contents.text); cpy.isCollapsed = this.isCollapsed; cpy.setTextWidth(this.textWidth()); + if (this.selectionID) { // for copy on write + cpy.selectionID = true; + } return cpy; }; @@ -12963,6 +12994,24 @@ CommentMorph.prototype.prepareToBeGrabbed = function (hand) { } }; +CommentMorph.prototype.selectForEdit = function () { + var scripts = this.parentThatIsA(ScriptsMorph), + rcvr = scripts ? scripts.scriptTarget() : null, + selected; + if (rcvr && rcvr.inheritsAttribute('scripts')) { + // copy on write: + this.selectionID = true; + rcvr.shadowAttribute('scripts'); + selected = detect(rcvr.scripts.allChildren(), function (m) { + return m.selectionID; + }); + delete this.selectionID; + delete selected.selectionID; + return selected; + } + return this; +}; + CommentMorph.prototype.snap = function (hand) { // passing the hand is optional (for when blocks are dragged & dropped) var scripts = this.parent, diff --git a/history.txt b/history.txt index e9ed8ed9..2cb3c51d 100755 --- a/history.txt +++ b/history.txt @@ -3454,6 +3454,11 @@ Fixes: ------ * objects: stop all scripts for a sprite when shadowing or inheriting its scripts +170622 +------ +* Morphic: support for copy-on-write worlds (“selectForEdit”) +* Blocks, Objects: shadow inherited scripts on dragging & dropping blocks and comments + Features: * polymorphic sprite-local custom blocks diff --git a/objects.js b/objects.js index 07939a35..7a6f2115 100644 --- a/objects.js +++ b/objects.js @@ -82,7 +82,7 @@ SpeechBubbleMorph, RingMorph, isNil, FileReader, TableDialogMorph, BlockEditorMorph, BlockDialogMorph, PrototypeHatBlockMorph, localize, TableMorph, TableFrameMorph, normalizeCanvas, BooleanSlotMorph, HandleMorph*/ -modules.objects = '2017-June-21'; +modules.objects = '2017-June-22'; var SpriteMorph; var StageMorph; @@ -5186,7 +5186,8 @@ SpriteMorph.prototype.shadowedAttributes = function () { SpriteMorph.prototype.shadowAttribute = function (aName) { var ide, wardrobe, - myself = this; + myself = this, + pos; if (!this.inheritsAttribute(aName)) { return; } @@ -5206,11 +5207,14 @@ SpriteMorph.prototype.shadowAttribute = function (aName) { this.costumes = wardrobe; } else if (aName === 'scripts') { ide.stage.threads.stopAllForReceiver(this); + pos = this.scripts.position(); this.scripts = this.exemplar.scripts.fullCopy(); if (ide && (contains(ide.currentSprite.allExemplars(), this))) { ide.createSpriteEditor(); ide.fixLayout('selectSprite'); this.scripts.fixMultiArgs(); + this.scripts.setPosition(pos); + ide.spriteEditor.adjustScrollBars(); } this.specimens().forEach(function (obj) { if (obj.inheritsAttribute('scripts')) {