extended block-search to include dropdown choices in custom blocks

pull/95/head
jmoenig 2020-11-27 09:11:34 +01:00
rodzic 3feaf21306
commit ae473fe8c1
4 zmienionych plików z 35 dodań i 5 usunięć

Wyświetl plik

@ -3,10 +3,11 @@
## in development:
* **Notable Changes:**
* searching for blocks and keyboard entry now includes thre contents of primitives' dropdown menus
* searching for blocks and keyboard entry now includes the contents of dropdown menus
### 2020-11-27
* objects: extended block-search to include dropdown choices in primitives
* byob, objects: extended block-search to include dropdown choices in custom blocks
### 2020-11-26
* blocks, objects: refactored input slot specs

Wyświetl plik

@ -14,7 +14,7 @@
<script src="src/gui.js?version=2020-11-23"></script>
<script src="src/paint.js?version=2020-05-17"></script>
<script src="src/lists.js?version=2020-07-01"></script>
<script src="src/byob.js?version=2020-10-07"></script>
<script src="src/byob.js?version=2020-11-27"></script>
<script src="src/tables.js?version=2020-10-06"></script>
<script src="src/sketch.js?version=2020-07-13"></script>
<script src="src/video.js?version=2019-06-27"></script>

Wyświetl plik

@ -97,7 +97,7 @@
/*global modules, CommandBlockMorph, SpriteMorph, TemplateSlotMorph, Map,
StringMorph, Color, DialogBoxMorph, ScriptsMorph, ScrollFrameMorph, WHITE,
Point, HandleMorph, HatBlockMorph, BlockMorph, detect, List, Process,
Point, HandleMorph, HatBlockMorph, BlockMorph, detect, List, Process, isString,
AlignmentMorph, ToggleMorph, InputFieldMorph, ReporterBlockMorph, StringMorph,
nop, radians, BoxMorph, ArrowMorph, PushButtonMorph, contains, InputSlotMorph,
ToggleButtonMorph, IDE_Morph, MenuMorph, copy, ToggleElementMorph, fontHeight,
@ -107,7 +107,7 @@ WatcherMorph, Variable, BooleanSlotMorph, XML_Serializer, SnapTranslator*/
// Global stuff ////////////////////////////////////////////////////////
modules.byob = '2020-October-07';
modules.byob = '2020-November-27';
// Declarations
@ -371,6 +371,32 @@ CustomBlockDefinition.prototype.parseChoices = function (string) {
return dict;
};
CustomBlockDefinition.prototype.menuSearchWords = function () {
// return a single string containing words that can be searched for
// inside my dropdown menus
var terms = [];
this.inputNames().forEach(slot => {
var menu = this.dropDownMenuOf(slot);
if (menu) {
if (isString(menu)) { // special menu, translates its values
menu = InputSlotMorph.prototype[menu](true);
terms.push(
Object.values(menu).map(entry => {
if (isNil(entry)) {return ''; }
if (entry instanceof Array) {
return localize(entry[0]);
}
return entry.toString();
}).join(' ')
);
} else { // assume a dictionary, take its keys
terms.push(Object.keys(menu).join(' '));
}
}
});
return terms.join(' ').toLowerCase();
};
CustomBlockDefinition.prototype.isReadOnlyInput = function (inputName) {
return this.declarations.has(inputName) &&
this.declarations.get(inputName)[3] === true;

Wyświetl plik

@ -3155,7 +3155,10 @@ SpriteMorph.prototype.blocksMatching = function (
blocksList.forEach(definition => {
if (contains(types, definition.type)) {
var spec = definition.localizedSpec(),
rel = relevance(labelOf(spec), search);
rel = relevance(labelOf(
spec) + ' ' + definition.menuSearchWords(),
search
);
if (rel !== -1) {
blocks.push([definition.templateInstance(), rel + '2']);
}