|
| 1 | + |
| 2 | +import { translate } from '../../utils/lang/i18n'; |
| 3 | + |
1 | 4 | /* eslint-disable func-names, no-underscore-dangle */ |
2 | 5 |
|
3 | 6 | /** |
@@ -38,7 +41,7 @@ Blockly.Flyout.prototype.scrollAnimationFraction = 1.0; |
38 | 41 | * @param {number} y The computed y origin of the flyout's SVG group. |
39 | 42 | * @protected |
40 | 43 | */ |
41 | | -Blockly.Flyout.prototype.positionAt_ = function(width, height, x, y) { |
| 44 | +Blockly.Flyout.prototype.positionAt_ = function (width, height, x, y) { |
42 | 45 | this.svgGroup_.setAttribute('width', width); |
43 | 46 | this.svgGroup_.setAttribute('height', height); |
44 | 47 |
|
@@ -73,26 +76,52 @@ Blockly.Flyout.prototype.positionAt_ = function(width, height, x, y) { |
73 | 76 | * @return {number} The width of the flyout. |
74 | 77 | * deriv-bot: Return actual width rather than this.DEFAULT_WIDTH. |
75 | 78 | */ |
76 | | -Blockly.Flyout.prototype.getWidth = function() { |
| 79 | +Blockly.Flyout.prototype.getWidth = function () { |
77 | 80 | return this.width_; |
78 | 81 | }; |
79 | 82 |
|
80 | 83 | const addSearchFlyout = (callback, xmlList, flyout) => { |
81 | 84 | let xmlSearchList = xmlList; |
82 | | - if (xmlList.type === Blockly.Search.NAME_TYPE) { |
83 | | - const blocksLength = Object.keys(xmlList.blocks).length; |
84 | | - const nodesLength = Object.keys(xmlList.nodes).length; |
85 | | - const noResult = !blocksLength && !nodesLength; |
86 | | - |
87 | | - xmlSearchList = |
88 | | - Blockly.Search.flyoutCategory(xmlList.blocks, flyout.workspace_, noResult); |
89 | | - xmlSearchList = xmlSearchList.concat(xmlList.nodes); |
| 85 | + if (xmlList.type === 'search') { |
| 86 | + const blocks = xmlList.blocks; |
| 87 | + const fn_blocks = xmlList.fnBlocks; |
| 88 | + const var_blocks = xmlList.varBlocks; |
| 89 | + const noResult = !blocks.length |
| 90 | + && !Object.keys(fn_blocks).length |
| 91 | + && !var_blocks.length; |
| 92 | + |
| 93 | + xmlSearchList = []; |
| 94 | + |
| 95 | + if (noResult) { |
| 96 | + const label = document.createElement('label'); |
| 97 | + label.setAttribute('text', translate('No Blocks Found')); |
| 98 | + xmlSearchList.push(label); |
| 99 | + } else { |
| 100 | + const label = document.createElement('label'); |
| 101 | + label.setAttribute('text', translate('Result(s)')); |
| 102 | + |
| 103 | + xmlSearchList.push(label); |
| 104 | + } |
| 105 | + |
| 106 | + if (Object.keys(fn_blocks).length) { |
| 107 | + const func_xml_list = Blockly.Procedures.flyoutCategory(flyout.workspace_); |
| 108 | + |
| 109 | + xmlSearchList = xmlSearchList.concat(func_xml_list); |
| 110 | + } |
| 111 | + |
| 112 | + if (var_blocks.length) { |
| 113 | + const var_xml_list = Blockly.DataCategory.search(var_blocks); |
| 114 | + |
| 115 | + xmlSearchList = xmlSearchList.concat(var_xml_list); |
| 116 | + } |
| 117 | + |
| 118 | + xmlSearchList = xmlSearchList.concat(blocks); |
90 | 119 | } |
91 | 120 |
|
92 | 121 | callback(xmlSearchList); |
93 | 122 | }; |
94 | 123 |
|
95 | 124 | const originalFlyoutShowFn = Blockly.Flyout.prototype.show; |
96 | | -Blockly.Flyout.prototype.show = function(xmlList){ |
| 125 | +Blockly.Flyout.prototype.show = function (xmlList) { |
97 | 126 | addSearchFlyout(originalFlyoutShowFn.bind(this), xmlList, this); |
98 | 127 | }; |
0 commit comments