Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add indexing of dropdown entries #2004

Closed
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions plugins/toolbox-search/src/block_searcher.ts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes to this file are unnecessary because the other PR added indexing.

Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@ export class BlockSearcher {
block.inputList.forEach((input) => {
input.fieldRow.forEach((field) => {
this.indexBlockText(field.getText(), blockType);
// Index the text of dropdown options.
// check if this is a dropdown
if (field instanceof Blockly.FieldDropdown) {
// get the options
const options = field.getOptions();
// iterate through the options
options.forEach((option) => {
// index the text of the option
// only add the option[0] if it is text
if (typeof option[0] === 'string') {
this.indexBlockText(option[0], blockType);
}
});
}
});
});
});
Expand Down
36 changes: 36 additions & 0 deletions plugins/toolbox-search/src/toolbox_search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,45 @@
this.flyoutItems_ = query ?
this.blockSearcher.blockTypesMatching(query).map(
(blockType) => {
// check the block if it has dropdowns
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove the inline comments throughout? I think the code is self-explanatory!

// get the block
const block = this.workspace_.newBlock(blockType);
// get the inputs
const inputs = block.inputList;
// iterate through the inputs
for (let input of inputs) {

Check failure on line 170 in plugins/toolbox-search/src/toolbox_search.ts

View workflow job for this annotation

GitHub Actions / lint

'input' is never reassigned. Use 'const' instead
// get the fields
const fields = input.fieldRow;
// iterate through the fields
for (let field of fields) {

Check failure on line 174 in plugins/toolbox-search/src/toolbox_search.ts

View workflow job for this annotation

GitHub Actions / lint

'field' is never reassigned. Use 'const' instead
// check if the field is a dropdown
if (field instanceof Blockly.FieldDropdown) {
// get the options
const options = field.getOptions();
// iterate through the options
for (let option of options) {

Check failure on line 180 in plugins/toolbox-search/src/toolbox_search.ts

View workflow job for this annotation

GitHub Actions / lint

'option' is never reassigned. Use 'const' instead
// check if the query is in the option
// make sure the option is text
if (typeof option[0] === 'string' &&

Check failure on line 183 in plugins/toolbox-search/src/toolbox_search.ts

View workflow job for this annotation

GitHub Actions / lint

Trailing spaces not allowed
option[0].toLowerCase().includes(query.toLowerCase())) {

Check failure on line 184 in plugins/toolbox-search/src/toolbox_search.ts

View workflow job for this annotation

GitHub Actions / lint

This line has a length of 83. Maximum allowed is 80

Check failure on line 184 in plugins/toolbox-search/src/toolbox_search.ts

View workflow job for this annotation

GitHub Actions / lint

Block must not be padded by blank lines

Check failure on line 185 in plugins/toolbox-search/src/toolbox_search.ts

View workflow job for this annotation

GitHub Actions / lint

Trailing spaces not allowed
let fields = {}

Check failure on line 186 in plugins/toolbox-search/src/toolbox_search.ts

View workflow job for this annotation

GitHub Actions / lint

'fields' is never reassigned. Use 'const' instead

Check failure on line 186 in plugins/toolbox-search/src/toolbox_search.ts

View workflow job for this annotation

GitHub Actions / lint

Missing semicolon

Check failure on line 186 in plugins/toolbox-search/src/toolbox_search.ts

View workflow job for this annotation

GitHub Actions / lint

Missing semicolon
fields[field.name] = option[1]
return {
kind: 'block',
type: blockType,
fields: fields
};
}
};
}
}
}

return {
kind: 'block',
type: blockType,

};
}) : [];

Expand Down
Loading