kopia lustrzana https://github.com/backface/turtlestitch
more arrow-function refactorings in blocks.js
rodzic
c7ff1a2757
commit
a4f4b88b0b
|
@ -7179,20 +7179,20 @@ ScriptsMorph.prototype.updateToolbar = function () {
|
||||||
|
|
||||||
ScriptsMorph.prototype.sortedElements = function () {
|
ScriptsMorph.prototype.sortedElements = function () {
|
||||||
// return all scripts and unattached comments
|
// return all scripts and unattached comments
|
||||||
var scripts = this.children.filter(function (each) {
|
var scripts = this.children.filter(each =>
|
||||||
return each instanceof CommentMorph ? !each.block : true;
|
each instanceof CommentMorph ? !each.block : true
|
||||||
});
|
);
|
||||||
scripts.sort(function (a, b) {
|
scripts.sort((a, b) =>
|
||||||
// make sure the prototype hat block always stays on top
|
// make sure the prototype hat block always stays on top
|
||||||
return a instanceof PrototypeHatBlockMorph ? 0 : a.top() - b.top();
|
a instanceof PrototypeHatBlockMorph ? 0 : a.top() - b.top()
|
||||||
});
|
);
|
||||||
return scripts;
|
return scripts;
|
||||||
};
|
};
|
||||||
|
|
||||||
// ScriptsMorph blocks layout fix
|
// ScriptsMorph blocks layout fix
|
||||||
|
|
||||||
ScriptsMorph.prototype.fixMultiArgs = function () {
|
ScriptsMorph.prototype.fixMultiArgs = function () {
|
||||||
this.forAllChildren(function (morph) {
|
this.forAllChildren(morph => {
|
||||||
if (morph instanceof MultiArgMorph) {
|
if (morph instanceof MultiArgMorph) {
|
||||||
morph.fixLayout();
|
morph.fixLayout();
|
||||||
}
|
}
|
||||||
|
@ -7494,9 +7494,7 @@ CommandSlotMorph.prototype.nestedBlock = function (block) {
|
||||||
} else {
|
} else {
|
||||||
return detect(
|
return detect(
|
||||||
this.children,
|
this.children,
|
||||||
function (child) {
|
child => child instanceof CommandBlockMorph
|
||||||
return child instanceof CommandBlockMorph;
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -7584,18 +7582,20 @@ CommandSlotMorph.prototype.attach = function () {
|
||||||
// for context menu demo and testing purposes
|
// for context menu demo and testing purposes
|
||||||
// override inherited version to adjust new owner's layout
|
// override inherited version to adjust new owner's layout
|
||||||
var choices = this.overlappedMorphs(),
|
var choices = this.overlappedMorphs(),
|
||||||
menu = new MenuMorph(this, 'choose new parent:'),
|
menu = new MenuMorph(this, 'choose new parent:');
|
||||||
myself = this;
|
|
||||||
|
|
||||||
choices.forEach(function (each) {
|
choices.forEach(each =>
|
||||||
menu.addItem(each.toString().slice(0, 50), function () {
|
menu.addItem(
|
||||||
each.add(myself);
|
each.toString().slice(0, 50),
|
||||||
myself.isDraggable = false;
|
() => {
|
||||||
if (each.fixLayout) {
|
each.add(this);
|
||||||
each.fixLayout();
|
this.isDraggable = false;
|
||||||
|
if (each.fixLayout) {
|
||||||
|
each.fixLayout();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
)
|
||||||
});
|
);
|
||||||
if (choices.length > 0) {
|
if (choices.length > 0) {
|
||||||
menu.popUpAtHand(this.world());
|
menu.popUpAtHand(this.world());
|
||||||
}
|
}
|
||||||
|
@ -8062,7 +8062,7 @@ CSlotMorph.prototype.mappedCode = function (definitions) {
|
||||||
partLines = (part.toString()).split('\n'),
|
partLines = (part.toString()).split('\n'),
|
||||||
rx = new RegExp('<#1>', 'g');
|
rx = new RegExp('<#1>', 'g');
|
||||||
|
|
||||||
codeLines.forEach(function (codeLine, idx) {
|
codeLines.forEach((codeLine, idx) => {
|
||||||
var prefix = '',
|
var prefix = '',
|
||||||
indent;
|
indent;
|
||||||
if (codeLine.trimLeft().indexOf('<#1>') === 0) {
|
if (codeLine.trimLeft().indexOf('<#1>') === 0) {
|
||||||
|
@ -8124,9 +8124,7 @@ CSlotMorph.prototype.loop = function () {
|
||||||
if (this.isLoop) {
|
if (this.isLoop) {
|
||||||
return detect(
|
return detect(
|
||||||
this.children,
|
this.children,
|
||||||
function (child) {
|
child => child instanceof SymbolMorph
|
||||||
return child instanceof SymbolMorph;
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -8545,18 +8543,14 @@ InputSlotMorph.prototype.getSpec = function () {
|
||||||
InputSlotMorph.prototype.contents = function () {
|
InputSlotMorph.prototype.contents = function () {
|
||||||
return detect(
|
return detect(
|
||||||
this.children,
|
this.children,
|
||||||
function (child) {
|
child => child instanceof StringMorph
|
||||||
return (child instanceof StringMorph);
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
InputSlotMorph.prototype.arrow = function () {
|
InputSlotMorph.prototype.arrow = function () {
|
||||||
return detect(
|
return detect(
|
||||||
this.children,
|
this.children,
|
||||||
function (child) {
|
child => child instanceof ArrowMorph
|
||||||
return (child instanceof ArrowMorph);
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -8719,35 +8713,32 @@ InputSlotMorph.prototype.messagesMenu = function () {
|
||||||
var dict = {},
|
var dict = {},
|
||||||
rcvr = this.parentThatIsA(BlockMorph).scriptTarget(),
|
rcvr = this.parentThatIsA(BlockMorph).scriptTarget(),
|
||||||
stage = rcvr.parentThatIsA(StageMorph),
|
stage = rcvr.parentThatIsA(StageMorph),
|
||||||
myself = this,
|
|
||||||
allNames = [];
|
allNames = [];
|
||||||
|
|
||||||
stage.children.concat(stage).forEach(function (morph) {
|
stage.children.concat(stage).forEach(morph => {
|
||||||
if (isSnapObject(morph)) {
|
if (isSnapObject(morph)) {
|
||||||
allNames = allNames.concat(morph.allMessageNames());
|
allNames = allNames.concat(morph.allMessageNames());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
allNames.forEach(function (name) {
|
allNames.forEach(name =>
|
||||||
dict[name] = name;
|
dict[name] = name
|
||||||
});
|
);
|
||||||
if (this.world().currentKey === 16) { // shift
|
if (this.world().currentKey === 16) { // shift
|
||||||
dict.__shout__go__ = ['__shout__go__'];
|
dict.__shout__go__ = ['__shout__go__'];
|
||||||
}
|
}
|
||||||
if (allNames.length > 0) {
|
if (allNames.length > 0) {
|
||||||
dict['~'] = null;
|
dict['~'] = null;
|
||||||
}
|
}
|
||||||
dict['new...'] = function () {
|
dict['new...'] = () =>
|
||||||
|
|
||||||
new DialogBoxMorph(
|
new DialogBoxMorph(
|
||||||
myself,
|
this,
|
||||||
myself.setContents,
|
this.setContents,
|
||||||
myself
|
this
|
||||||
).prompt(
|
).prompt(
|
||||||
'Message name',
|
'Message name',
|
||||||
null,
|
null,
|
||||||
myself.world()
|
this.world()
|
||||||
);
|
);
|
||||||
};
|
|
||||||
return dict;
|
return dict;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue