From ecd436f2fb63579f4d28e693c31c1f03233e0b85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20M=C3=B6nig?= Date: Wed, 25 May 2022 16:18:02 +0200 Subject: [PATCH] update manual custom block-type changes in data references --- HISTORY.md | 1 + snap.html | 2 +- src/byob.js | 33 ++++++++++++++++++++++++++++----- src/threads.js | 2 -- 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index cf31750f..d8b954be 100755 --- a/HISTORY.md +++ b/HISTORY.md @@ -51,6 +51,7 @@ ### 2022-05-25 * threads: update programmatic custom block-type changes in data references +* byob: update manual custom block-type changes in data references ### 2022-05-23 * blocks: fixed block label color when expanding or inserting variadic infix slots diff --git a/snap.html b/snap.html index 15b12113..81c8f4d8 100755 --- a/snap.html +++ b/snap.html @@ -23,7 +23,7 @@ - + diff --git a/src/byob.js b/src/byob.js index fdf9d67b..00573400 100644 --- a/src/byob.js +++ b/src/byob.js @@ -111,7 +111,7 @@ ArgLabelMorph*/ // Global stuff //////////////////////////////////////////////////////// -modules.byob = '2022-May-20'; +modules.byob = '2022-May-25'; // Declarations @@ -2665,12 +2665,27 @@ BlockEditorMorph.prototype.refreshAllBlockInstances = function (oldSpec) { var def = this.definition, template = this.target.paletteBlockInstance(def); - if (this.definition.isGlobal) { - this.target.allBlockInstances(this.definition).reverse().forEach( + function isMajorTypeChange(oldType) { + var rep = ['reporter', 'predicate'], + type = def.type; + return (type === 'command' && rep.includes(oldType)) || + (oldType == 'command' && rep.includes(type)); + } + + if (def.isGlobal) { + this.target.allBlockInstances(def).reverse().forEach( block => block.refresh() ); this.target.parentThatIsA(StageMorph).allContextsUsing(def).forEach( - context => context.changed() + context => { + if (context.expression.isCustomBlock && + context.expression.isUnattached() && + isMajorTypeChange(context.expression.type()) + ) { + context.expression = def.blockInstance(); + } + context.changed(); + } ); } else { this.target.allDependentInvocationsOf(oldSpec).reverse().forEach( @@ -2680,7 +2695,15 @@ BlockEditorMorph.prototype.refreshAllBlockInstances = function (oldSpec) { def.blockSpec(), this.target ).forEach( - context => context.changed() + context => { + if (context.expression.isCustomBlock && + context.expression.isUnattached() && + isMajorTypeChange(context.expression.type()) + ) { + context.expression = def.blockInstance(); + } + context.changed(); + } ); } if (template) { diff --git a/src/threads.js b/src/threads.js index 2e642b3d..f5746137 100644 --- a/src/threads.js +++ b/src/threads.js @@ -5724,8 +5724,6 @@ Process.prototype.doSetBlockAttribute = function (attribute, block, val) { ); } } - - break; case 'scope': if (isInUse()) {