preserve contents of variadic inputs when editing or translating a custom blocks

snap8
Jens Mönig 2022-02-09 16:55:31 +01:00
rodzic 0f046b2330
commit 09e561deb7
4 zmienionych plików z 49 dodań i 20 usunięć

Wyświetl plik

@ -5,11 +5,13 @@
* **New Features:**
* **Notable Changes:**
* **Notable Fixes:**
* preserve contents of variadic inputs when editing or translating a custom blocks
* **Documentation Updates:**
* **Translation Updates:**
### 2022-02-09
* new dev version
* blocks, byob: preserve contents of variadic inputs when editing or translating a custom blocks
## 7.1.3:
* **New Features:**

Wyświetl plik

@ -16,14 +16,14 @@
<script src="src/morphic.js?version=2022-01-28"></script>
<script src="src/symbols.js?version=2021-03-03"></script>
<script src="src/widgets.js?version=2021-17-09"></script>
<script src="src/blocks.js?version=2022-01-30"></script>
<script src="src/blocks.js?version=2022-02-09"></script>
<script src="src/threads.js?version=2022-01-31"></script>
<script src="src/objects.js?version=2022-02-07"></script>
<script src="src/scenes.js?version=2021-11-24"></script>
<script src="src/gui.js?version=2022-02-09"></script>
<script src="src/paint.js?version=2021-07-05"></script>
<script src="src/lists.js?version=2022-02-07"></script>
<script src="src/byob.js?version=2022-01-07"></script>
<script src="src/byob.js?version=2022-02-09"></script>
<script src="src/tables.js?version=2022-01-28"></script>
<script src="src/sketch.js?version=2021-11-03"></script>
<script src="src/video.js?version=2019-06-27"></script>

Wyświetl plik

@ -161,7 +161,7 @@ CostumeIconMorph, SoundIconMorph, SVG_Costume*/
// Global stuff ////////////////////////////////////////////////////////
modules.blocks = '2022-January-30';
modules.blocks = '2022-February-09';
var SyntaxElementMorph;
var BlockMorph;
@ -1250,7 +1250,7 @@ SyntaxElementMorph.prototype.replaceInput = function (oldArg, newArg) {
oldArg.inputs().forEach(inp => // preserve nested reporters
oldArg.replaceInput(inp, new InputSlotMorph())
);
if (this.dynamicInputLabels) {
if (this.dynamicInputLabels && newArg instanceof ReporterBlockMorph) {
replacement = new ArgLabelMorph(newArg);
}
}

Wyświetl plik

@ -104,13 +104,14 @@ nop, radians, BoxMorph, ArrowMorph, PushButtonMorph, contains, InputSlotMorph,
ToggleButtonMorph, IDE_Morph, MenuMorph, ToggleElementMorph, fontHeight, isNil,
StageMorph, SyntaxElementMorph, CommentMorph, localize, CSlotMorph, Variable,
MorphicPreferences, SymbolMorph, CursorMorph, VariableFrame, BooleanSlotMorph,
WatcherMorph, XML_Serializer, SnapTranslator, SnapExtensions*/
WatcherMorph, XML_Serializer, SnapTranslator, SnapExtensions, MultiArgMorph,
ArgLabelMorph*/
/*jshint esversion: 6*/
// Global stuff ////////////////////////////////////////////////////////
modules.byob = '2022-January-07';
modules.byob = '2022-February-09';
// Declarations
@ -747,34 +748,60 @@ CustomCommandBlockMorph.prototype.refresh = function (aDefinition) {
CustomCommandBlockMorph.prototype.restoreInputs = function (oldInputs) {
// try to restore my previous inputs when my spec has been changed
var i = 0,
old;
var newInputs = this.inputs(),
len = Math.max(oldInputs.length, newInputs.length),
scripts = this.parentThatIsA(ScriptsMorph),
old,
inp,
i;
function preserve(item) {
// keep unused blocks around in the scripting area
if (item instanceof MultiArgMorph) {
return item.inputs().forEach(slot => preserve(slot));
}
if (item instanceof BlockMorph && scripts) {
scripts.add(item);
item.moveBy(new Point(20, 20));
item.fixBlockColor();
}
}
if (this.isPrototype) {return; }
this.cachedInputs = null;
this.inputs().forEach(inp => {
for (i = 0; i < len; i += 1) {
inp = newInputs[i];
old = oldInputs[i];
if (old instanceof ReporterBlockMorph &&
if (old instanceof ArgLabelMorph) {
old = old.argMorph();
}
if (old instanceof ReporterBlockMorph && inp &&
(!(inp instanceof TemplateSlotMorph))) {
this.replaceInput(inp, old.fullCopy());
} else if (old instanceof InputSlotMorph
&& inp instanceof InputSlotMorph) {
} else if (old instanceof InputSlotMorph &&
inp instanceof InputSlotMorph) {
if (old.isEmptySlot()) {
inp.setContents('');
} else {
inp.setContents(old.evaluate());
}
} else if (old instanceof BooleanSlotMorph
&& inp instanceof BooleanSlotMorph) {
} else if (old instanceof BooleanSlotMorph &&
inp instanceof BooleanSlotMorph) {
inp.setContents(old.evaluate());
} else if (old instanceof TemplateSlotMorph
&& inp instanceof TemplateSlotMorph) {
} else if (old instanceof TemplateSlotMorph &&
inp instanceof TemplateSlotMorph) {
inp.setContents(old.evaluate());
} else if (old instanceof CSlotMorph
&& inp instanceof CSlotMorph) {
} else if (old instanceof CSlotMorph &&
inp instanceof CSlotMorph) {
inp.nestedBlock(old.evaluate());
} else if (old instanceof MultiArgMorph &&
inp instanceof MultiArgMorph &&
(old.slotSpec === inp.slotSpec)) {
this.replaceInput(inp, old.fullCopy());
} else {
preserve(old);
}
i += 1;
});
}
this.cachedInputs = null;
};