Class: WorkspaceSearch
Defined in: workspace_search.ts:14
Class for workspace search.
Implements
IPositionableIAutoHideable
Properties index
| Property | Description |
|---|---|
| actionDiv | The div that holds the search bar actions. |
| blocks | A list of matching blocks that came up in the search. |
| caseSensitive | Whether search should be case sensitive. |
| currentBlockIndex | Index of the currently "selected" block in the blocks array. |
| id | The unique id for this component. |
| preserveSelected | Whether search should preserve the currently selected block by default. |
| searchOnInput | Whether to search as input changes as opposed to on enter. |
| searchText | The search text. |
Methods index
| Method | Description |
|---|---|
| addActionBtn | Add a button to the action div. This must be called after the init function has been called. |
| autoHide | Hides the search bar. Called from WorkspaceSvg.hideChaff, for example when the user clicks a block. |
| clearBlocks | Clears the selection group and current block. |
| close | Closes the search bar and releases ephemeral focus. |
| createCloseBtn | Creates the button used for closing the search bar. |
| createDom | Creates and injects the search bar's DOM. |
| createNextBtn | Creates the button used to get the next block in the list. |
| createPreviousBtn | Creates the button used to get the previous block in the list. |
| createTextInput | Creates the text input for the search bar. |
| dispose | Disposes of workspace search. Unlink from all DOM elements and remove all event listeners to prevent memory leaks. |
| getBoundingRectangle | Returns the bounding rectangle of the UI element in pixel units relative to the Blockly injection div. |
| getMatchingBlocks | Returns blocks that match the given search text. |
| getNonMatchingBlocks | Returns non-matching blocks in the search pool. |
| highlightCurrentSelection | Adds "current selection" highlight to the provided block. Highlights the provided block as the "current selection". |
| highlightSearchGroup | Adds highlight to the provided blocks. |
| init | Initializes the workspace search bar. |
| isBlockMatch | Returns whether the given block matches the search text. |
| next | Selects the next block. |
| open | Opens the search bar. |
| position | Positions the workspace search field. It is positioned in the opposite corner to the corner the categories/toolbox starts at. |
| previous | Selects the previous block. |
| searchAndHighlight | Searches the workspace for the current search term, highlights matching blocks, and greys non-matching blocks. |
| setCurrentBlock | Changes the currently "selected" block and adds extra highlight. |
| setSearchPlaceholder | Sets the placeholder text for the search bar text input. |
| unhighlightCurrentSelection | Removes "current selection" highlight from provided block. |
| unhighlightSearchGroup | Removes highlight from the provided blocks. |
Constructors
Constructor
new WorkspaceSearch(workspace): WorkspaceSearch;
Defined in: workspace_search.ts:102
Class for workspace search.
Parameters
| Parameter | Type | Description |
|---|---|---|
workspace | WorkspaceSvg | The workspace the search bar sits in. |
Returns
WorkspaceSearch
Properties
actionDiv
protected actionDiv: HTMLElement | null = null;
Defined in: workspace_search.ts:30
The div that holds the search bar actions.
blocks
protected blocks: BlockSvg[] = [];
Defined in: workspace_search.ts:45
A list of matching blocks that came up in the search.
caseSensitive
caseSensitive: boolean = false;
Defined in: workspace_search.ts:84
Whether search should be case sensitive.
currentBlockIndex
protected currentBlockIndex: number = -1;
Defined in: workspace_search.ts:69
Index of the currently "selected" block in the blocks array.
id
id: string = 'workspaceSearch';
Defined in: workspace_search.ts:20
The unique id for this component.
Implementation of
Blockly.IPositionable.id
preserveSelected
preserveSelected: boolean = true;
Defined in: workspace_search.ts:89
Whether search should preserve the currently selected block by default.
searchOnInput
searchOnInput: boolean = true;
Defined in: workspace_search.ts:79
Whether to search as input changes as opposed to on enter.
searchText
protected searchText: string = '';
Defined in: workspace_search.ts:74
The search text.
Methods
addActionBtn()
addActionBtn(btn, onClickFn): void;
Defined in: workspace_search.ts:248
Add a button to the action div. This must be called after the init function has been called.
Parameters
| Parameter | Type | Description |
|---|---|---|
btn | HTMLButtonElement | The button to add the event listener to. |
onClickFn | () => void | The function to call when the user clicks on or hits enter on the button. |
Returns
void
autoHide()
autoHide(onlyClosePopups): void;
Defined in: workspace_search.ts:531
Hides the search bar. Called from WorkspaceSvg.hideChaff, for example when the user clicks a block.
Parameters
| Parameter | Type | Description |
|---|---|---|
onlyClosePopups | boolean | Whether only popups should be closed. |
Returns
void
Implementation of
Blockly.IAutoHideable.autoHide
clearBlocks()
clearBlocks(): void;
Defined in: workspace_search.ts:701
Clears the selection group and current block.
Returns
void
close()
close(): void;
Defined in: workspace_search.ts:511
Closes the search bar and releases ephemeral focus.
Returns
void
createCloseBtn()
protected createCloseBtn(): HTMLButtonElement;
Defined in: workspace_search.ts:300
Creates the button used for closing the search bar.
Returns
HTMLButtonElement
A button for closing the search bar.
createDom()
protected createDom(): void;
Defined in: workspace_search.ts:146
Creates and injects the search bar's DOM.
Returns
void
createNextBtn()
protected createNextBtn(): HTMLButtonElement;
Defined in: workspace_search.ts:276
Creates the button used to get the next block in the list.
Returns
HTMLButtonElement
The next button.
createPreviousBtn()
protected createPreviousBtn(): HTMLButtonElement;
Defined in: workspace_search.ts:288
Creates the button used to get the previous block in the list.
Returns
HTMLButtonElement
The previous button.
createTextInput()
protected createTextInput(): HTMLInputElement;
Defined in: workspace_search.ts:258
Creates the text input for the search bar.
Returns
HTMLInputElement
A text input for the search bar.
dispose()
dispose(): void;
Defined in: workspace_search.ts:128
Disposes of workspace search. Unlink from all DOM elements and remove all event listeners to prevent memory leaks.
Returns
void
getBoundingRectangle()
getBoundingRectangle(): Rect | null;
Defined in: workspace_search.ts:356
Returns the bounding rectangle of the UI element in pixel units relative to the Blockly injection div.
Returns
Rect | null
The component’s bounding box. Null in this case since we don't need other elements to avoid the workspace search field.
Implementation of
Blockly.IPositionable.getBoundingRectangle
getMatchingBlocks()
protected getMatchingBlocks(
workspace?,
searchText?,
caseSensitive?
): BlockSvg[];
Defined in: workspace_search.ts:669
Returns blocks that match the given search text.
Parameters
| Parameter | Type | Description |
|---|---|---|
workspace? | WorkspaceSvg | The workspace to search. |
searchText? | string | The search text. |
caseSensitive? | boolean | Whether the search should be case sensitive. |
Returns
BlockSvg[]
The blocks that match the search text.
getNonMatchingBlocks()
protected getNonMatchingBlocks(): BlockSvg[];
Defined in: workspace_search.ts:691
Returns non-matching blocks in the search pool.
Returns
BlockSvg[]
The blocks that do not match the search text.
highlightCurrentSelection()
protected highlightCurrentSelection(currentBlock): void;
Defined in: workspace_search.ts:750
Adds "current selection" highlight to the provided block. Highlights the provided block as the "current selection".
Parameters
| Parameter | Type | Description |
|---|---|---|
currentBlock | BlockSvg | The block to highlight. |
Returns
void
highlightSearchGroup()
protected highlightSearchGroup(blocks?): void;
Defined in: workspace_search.ts:770
Adds highlight to the provided blocks.
Parameters
| Parameter | Type | Description |
|---|---|---|
blocks? | BlockSvg[] | The blocks to highlight. |
Returns
void
init()
init(): void;
Defined in: workspace_search.ts:107
Initializes the workspace search bar.
Returns
void
isBlockMatch()
protected isBlockMatch(
block,
searchText,
caseSensitive?
): boolean;
Defined in: workspace_search.ts:636
Returns whether the given block matches the search text.
Parameters
| Parameter | Type | Description |
|---|---|---|
block | BlockSvg | The block to check. |
searchText | string | The search text. Note if the search is case insensitive, this will be passed already converted to lowercase letters. |
caseSensitive? | boolean | Whether the search is case sensitive. |
Returns
boolean
True if the block is a match, false otherwise.
next()
next(): void;
Defined in: workspace_search.ts:447
Selects the next block.
Returns
void
open()
open(): void;
Defined in: workspace_search.ts:493
Opens the search bar.
Returns
void
position()
position(metrics, savedPositions): void;
Defined in: workspace_search.ts:369
Positions the workspace search field. It is positioned in the opposite corner to the corner the categories/toolbox starts at.
Parameters
| Parameter | Type | Description |
|---|---|---|
metrics | UiMetrics | The workspace metrics. |
savedPositions | Rect[] | List of rectangles that are already on the workspace. |
Returns
void
Implementation of
Blockly.IPositionable.position
previous()
previous(): void;
Defined in: workspace_search.ts:440
Selects the previous block.
Returns
void
searchAndHighlight()
searchAndHighlight(searchText, preserveCurrent?): void;
Defined in: workspace_search.ts:581
Searches the workspace for the current search term, highlights matching blocks, and greys non-matching blocks.
Parameters
| Parameter | Type | Description |
|---|---|---|
searchText | string | The search text. |
preserveCurrent? | boolean | Whether to preserve the current block if it is included in the new matching blocks. |
Returns
void
setCurrentBlock()
protected setCurrentBlock(index): void;
Defined in: workspace_search.ts:468
Changes the currently "selected" block and adds extra highlight.
Parameters
| Parameter | Type | Description |
|---|---|---|
index | number | Index of block to set as current. Number is wrapped. |
Returns
void
setSearchPlaceholder()
setSearchPlaceholder(placeholderText): void;
Defined in: workspace_search.ts:456
Sets the placeholder text for the search bar text input.
Parameters
| Parameter | Type | Description |
|---|---|---|
placeholderText | string | The placeholder text. |
Returns
void
unhighlightCurrentSelection()
protected unhighlightCurrentSelection(currentBlock): void;
Defined in: workspace_search.ts:760
Removes "current selection" highlight from provided block.
Parameters
| Parameter | Type | Description |
|---|---|---|
currentBlock | BlockSvg | The block to unhighlight. |
Returns
void
unhighlightSearchGroup()
protected unhighlightSearchGroup(blocks?): void;
Defined in: workspace_search.ts:782
Removes highlight from the provided blocks.
Parameters
| Parameter | Type | Description |
|---|---|---|
blocks? | BlockSvg[] | The blocks to unhighlight. |
Returns
void