From 8001845706a80a3e4cd0911faeceb128675b99a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20M=C3=B6nig?= Date: Sun, 17 Jan 2016 23:44:30 +0100 Subject: [PATCH] =?UTF-8?q?preserve=20custom=20block=20instances=E2=80=99?= =?UTF-8?q?=20block=20var=20values=20when=20editing=20their=20definition?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- byob.js | 16 ++++++++++------ history.txt | 5 +++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/byob.js b/byob.js index b546cfea..c1dbd04e 100644 --- a/byob.js +++ b/byob.js @@ -104,11 +104,11 @@ contains, InputSlotMorph, ToggleButtonMorph, IDE_Morph, MenuMorph, copy, ToggleElementMorph, Morph, fontHeight, StageMorph, SyntaxElementMorph, SnapSerializer, CommentMorph, localize, CSlotMorph, SpeechBubbleMorph, MorphicPreferences, SymbolMorph, isNil, CursorMorph, VariableFrame, -WatcherMorph*/ +WatcherMorph, Variable*/ // Global stuff //////////////////////////////////////////////////////// -modules.byob = '2016-January-11'; +modules.byob = '2016-January-17'; // Declarations @@ -420,11 +420,15 @@ CustomCommandBlockMorph.prototype.init = function (definition, isProto) { } }; -CustomCommandBlockMorph.prototype.initializeVariables = function () { +CustomCommandBlockMorph.prototype.initializeVariables = function (oldVars) { var myself = this; this.variables = new VariableFrame(); this.definition.variableNames.forEach(function (name) { - myself.variables.addVar(name); + var v = oldVars ? oldVars[name] : null; + myself.variables.addVar( + name, + v instanceof Variable ? v.value : null + ); }); }; @@ -463,8 +467,8 @@ CustomCommandBlockMorph.prototype.refresh = function (silently) { }); // initialize block vars - // to do: preserve values of unchanged variable names - this.initializeVariables(); + // preserve values of unchanged variable names + this.initializeVariables(this.variables.vars); // make (double) sure I'm colored correctly this.forceNormalColoring(); diff --git a/history.txt b/history.txt index a5de042f..6d7ce58b 100755 --- a/history.txt +++ b/history.txt @@ -2849,3 +2849,8 @@ end - bulk of 151215 160116 ------ * Blocks: fixed a multi-line input slot layout glitch + +160117 +------ +* BYOB: preserve custom block instances’ block var values when editing their definition +