kopia lustrzana https://github.com/backface/turtlestitch
refactorings for scripts in blocks.js
rodzic
8af2a856b8
commit
e55f35f575
130
src/blocks.js
130
src/blocks.js
|
@ -5605,10 +5605,8 @@ ReporterBlockMorph.prototype.determineSlotSpec = function () {
|
||||||
// private - answer the spec of the slot I'm in, if any
|
// private - answer the spec of the slot I'm in, if any
|
||||||
var parts, idx;
|
var parts, idx;
|
||||||
if (this.parent instanceof BlockMorph) {
|
if (this.parent instanceof BlockMorph) {
|
||||||
parts = this.parent.parts().filter(
|
parts = this.parent.parts().filter(part =>
|
||||||
function (part) {
|
!(part instanceof BlockHighlightMorph)
|
||||||
return !(part instanceof BlockHighlightMorph);
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
idx = parts.indexOf(this);
|
idx = parts.indexOf(this);
|
||||||
if (idx !== -1) {
|
if (idx !== -1) {
|
||||||
|
@ -6255,9 +6253,9 @@ RingMorph.prototype.embed = function (aBlock, inputNames) {
|
||||||
// set my inputs, if any
|
// set my inputs, if any
|
||||||
slot = this.parts()[1];
|
slot = this.parts()[1];
|
||||||
if (inputNames) {
|
if (inputNames) {
|
||||||
inputNames.forEach(function (name) {
|
inputNames.forEach(name =>
|
||||||
slot.addInput(name);
|
slot.addInput(name)
|
||||||
});
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ensure zebra coloring
|
// ensure zebra coloring
|
||||||
|
@ -6381,15 +6379,15 @@ ScriptsMorph.prototype.fullCopy = function () {
|
||||||
if (this.focus) {
|
if (this.focus) {
|
||||||
this.focus.stopEditing();
|
this.focus.stopEditing();
|
||||||
}
|
}
|
||||||
this.children.forEach(function (morph) {
|
this.children.forEach(morph => {
|
||||||
if (!morph.block) { // omit anchored comments
|
if (!morph.block) { // omit anchored comments
|
||||||
child = morph.fullCopy();
|
child = morph.fullCopy();
|
||||||
cpy.add(child);
|
cpy.add(child);
|
||||||
child.setPosition(morph.position().subtract(pos));
|
child.setPosition(morph.position().subtract(pos));
|
||||||
if (child instanceof BlockMorph) {
|
if (child instanceof BlockMorph) {
|
||||||
child.allComments().forEach(function (comment) {
|
child.allComments().forEach(comment =>
|
||||||
comment.align(child);
|
comment.align(child)
|
||||||
});
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -6547,19 +6545,19 @@ ScriptsMorph.prototype.showCSlotWrapFeedback = function (srcBlock, trgBlock) {
|
||||||
ScriptsMorph.prototype.closestInput = function (reporter, hand) {
|
ScriptsMorph.prototype.closestInput = function (reporter, hand) {
|
||||||
// passing the hand is optional (when dragging reporters)
|
// passing the hand is optional (when dragging reporters)
|
||||||
var fb = reporter.fullBoundsNoShadow(),
|
var fb = reporter.fullBoundsNoShadow(),
|
||||||
stacks = this.children.filter(function (child) {
|
stacks = this.children.filter(child =>
|
||||||
return (child instanceof BlockMorph) &&
|
(child instanceof BlockMorph) &&
|
||||||
(child.fullBounds().intersects(fb));
|
(child.fullBounds().intersects(fb))
|
||||||
}),
|
),
|
||||||
blackList = reporter.allInputs(),
|
blackList = reporter.allInputs(),
|
||||||
handPos,
|
handPos,
|
||||||
target,
|
target,
|
||||||
all;
|
all;
|
||||||
|
|
||||||
all = [];
|
all = [];
|
||||||
stacks.forEach(function (stack) {
|
stacks.forEach(stack =>
|
||||||
all = all.concat(stack.allInputs());
|
all = all.concat(stack.allInputs())
|
||||||
});
|
);
|
||||||
if (all.length === 0) {return null; }
|
if (all.length === 0) {return null; }
|
||||||
|
|
||||||
function touchingVariadicArrowsIfAny(inp, point) {
|
function touchingVariadicArrowsIfAny(inp, point) {
|
||||||
|
@ -6577,18 +6575,17 @@ ScriptsMorph.prototype.closestInput = function (reporter, hand) {
|
||||||
handPos = hand.position();
|
handPos = hand.position();
|
||||||
target = detect(
|
target = detect(
|
||||||
all,
|
all,
|
||||||
function (input) {
|
input => (input instanceof InputSlotMorph ||
|
||||||
return (input instanceof InputSlotMorph
|
(input instanceof ArgMorph &&
|
||||||
|| (input instanceof ArgMorph
|
!(input instanceof CommandSlotMorph) &&
|
||||||
&& !(input instanceof CommandSlotMorph)
|
!(input instanceof MultiArgMorph)
|
||||||
&& !(input instanceof MultiArgMorph))
|
) ||
|
||||||
|| (input instanceof RingMorph
|
(input instanceof RingMorph && !input.contents()) ||
|
||||||
&& !input.contents())
|
input.isEmptySlot()
|
||||||
|| input.isEmptySlot())
|
) &&
|
||||||
&& !input.isLocked()
|
!input.isLocked() &&
|
||||||
&& input.bounds.containsPoint(handPos)
|
input.bounds.containsPoint(handPos) &&
|
||||||
&& !contains(blackList, input);
|
!contains(blackList, input)
|
||||||
}
|
|
||||||
);
|
);
|
||||||
if (target) {
|
if (target) {
|
||||||
return target;
|
return target;
|
||||||
|
@ -6596,17 +6593,15 @@ ScriptsMorph.prototype.closestInput = function (reporter, hand) {
|
||||||
}
|
}
|
||||||
target = detect(
|
target = detect(
|
||||||
all,
|
all,
|
||||||
function (input) {
|
input => (input instanceof InputSlotMorph ||
|
||||||
return (input instanceof InputSlotMorph
|
input instanceof ArgMorph ||
|
||||||
|| input instanceof ArgMorph
|
(input instanceof RingMorph && !input.contents()) ||
|
||||||
|| (input instanceof RingMorph
|
input.isEmptySlot()
|
||||||
&& !input.contents())
|
) &&
|
||||||
|| input.isEmptySlot())
|
!input.isLocked() &&
|
||||||
&& !input.isLocked()
|
input.bounds.intersects(fb) &&
|
||||||
&& input.bounds.intersects(fb)
|
!contains(blackList, input) &&
|
||||||
&& !contains(blackList, input)
|
touchingVariadicArrowsIfAny(input)
|
||||||
&& touchingVariadicArrowsIfAny(input);
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
if (target) {
|
if (target) {
|
||||||
return target;
|
return target;
|
||||||
|
@ -6617,13 +6612,11 @@ ScriptsMorph.prototype.closestInput = function (reporter, hand) {
|
||||||
handPos = hand.position();
|
handPos = hand.position();
|
||||||
target = detect(
|
target = detect(
|
||||||
all,
|
all,
|
||||||
function (input) {
|
input => (input !== reporter) &&
|
||||||
return (input !== reporter)
|
!input.isLocked() &&
|
||||||
&& !input.isLocked()
|
input.bounds.containsPoint(handPos) &&
|
||||||
&& input.bounds.containsPoint(handPos)
|
!(input.parent instanceof PrototypeHatBlockMorph) &&
|
||||||
&& !(input.parent instanceof PrototypeHatBlockMorph)
|
!contains(blackList, input)
|
||||||
&& !contains(blackList, input);
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
if (target) {
|
if (target) {
|
||||||
return target;
|
return target;
|
||||||
|
@ -6631,32 +6624,29 @@ ScriptsMorph.prototype.closestInput = function (reporter, hand) {
|
||||||
}
|
}
|
||||||
return detect(
|
return detect(
|
||||||
all,
|
all,
|
||||||
function (input) {
|
input => (input !== reporter) &&
|
||||||
return (input !== reporter)
|
!input.isLocked() &&
|
||||||
&& !input.isLocked()
|
input.fullBounds().intersects(fb) &&
|
||||||
&& input.fullBounds().intersects(fb)
|
!(input.parent instanceof PrototypeHatBlockMorph) &&
|
||||||
&& !(input.parent instanceof PrototypeHatBlockMorph)
|
!contains(blackList, input)
|
||||||
&& !contains(blackList, input);
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
ScriptsMorph.prototype.closestBlock = function (comment, hand) {
|
ScriptsMorph.prototype.closestBlock = function (comment, hand) {
|
||||||
// passing the hand is optional (when dragging comments)
|
// passing the hand is optional (when dragging comments)
|
||||||
var fb = comment.bounds,
|
var fb = comment.bounds,
|
||||||
stacks = this.children.filter(function (child) {
|
stacks = this.children.filter(child =>
|
||||||
return (child instanceof BlockMorph) &&
|
(child instanceof BlockMorph) &&
|
||||||
(child.fullBounds().intersects(fb));
|
(child.fullBounds().intersects(fb))
|
||||||
}),
|
),
|
||||||
handPos,
|
handPos,
|
||||||
target,
|
target,
|
||||||
all;
|
all;
|
||||||
|
|
||||||
all = [];
|
all = [];
|
||||||
stacks.forEach(function (stack) {
|
stacks.forEach(stack => {
|
||||||
all = all.concat(stack.allChildren().slice(0).reverse().filter(
|
all = all.concat(stack.allChildren().slice(0).reverse().filter(
|
||||||
function (child) {return child instanceof BlockMorph &&
|
child => child instanceof BlockMorph && !child.isTemplate
|
||||||
!child.isTemplate; }
|
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
if (all.length === 0) {return null; }
|
if (all.length === 0) {return null; }
|
||||||
|
@ -6665,11 +6655,9 @@ ScriptsMorph.prototype.closestBlock = function (comment, hand) {
|
||||||
handPos = hand.position();
|
handPos = hand.position();
|
||||||
target = detect(
|
target = detect(
|
||||||
all,
|
all,
|
||||||
function (block) {
|
block => !block.comment &&
|
||||||
return !block.comment
|
!block.isPrototype &&
|
||||||
&& !block.isPrototype
|
block.bounds.containsPoint(handPos)
|
||||||
&& block.bounds.containsPoint(handPos);
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
if (target) {
|
if (target) {
|
||||||
return target;
|
return target;
|
||||||
|
@ -6677,11 +6665,9 @@ ScriptsMorph.prototype.closestBlock = function (comment, hand) {
|
||||||
}
|
}
|
||||||
return detect(
|
return detect(
|
||||||
all,
|
all,
|
||||||
function (block) {
|
block => !block.comment &&
|
||||||
return !block.comment
|
!block.isPrototype &&
|
||||||
&& !block.isPrototype
|
block.bounds.intersects(fb)
|
||||||
&& block.bounds.intersects(fb);
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue