Skip to main content

Class: WorkspaceSearch

Defined in: workspace_search.ts:14

Class for workspace search.

Implements​

  • IPositionable
  • IAutoHideable

Properties index​

PropertyDescription
actionDivThe div that holds the search bar actions.
blocksA list of matching blocks that came up in the search.
caseSensitiveWhether search should be case sensitive.
currentBlockIndexIndex of the currently "selected" block in the blocks array.
idThe unique id for this component.
preserveSelectedWhether search should preserve the currently selected block by default.
searchOnInputWhether to search as input changes as opposed to on enter.
searchTextThe search text.

Methods index​

MethodDescription
addActionBtnAdd a button to the action div. This must be called after the init function has been called.
autoHideHides the search bar. Called from WorkspaceSvg.hideChaff, for example when the user clicks a block.
clearBlocksClears the selection group and current block.
closeCloses the search bar and releases ephemeral focus.
createCloseBtnCreates the button used for closing the search bar.
createDomCreates and injects the search bar's DOM.
createNextBtnCreates the button used to get the next block in the list.
createPreviousBtnCreates the button used to get the previous block in the list.
createTextInputCreates the text input for the search bar.
disposeDisposes of workspace search. Unlink from all DOM elements and remove all event listeners to prevent memory leaks.
getBoundingRectangleReturns the bounding rectangle of the UI element in pixel units relative to the Blockly injection div.
getMatchingBlocksReturns blocks that match the given search text.
getNonMatchingBlocksReturns non-matching blocks in the search pool.
highlightCurrentSelectionAdds "current selection" highlight to the provided block. Highlights the provided block as the "current selection".
highlightSearchGroupAdds highlight to the provided blocks.
initInitializes the workspace search bar.
isBlockMatchReturns whether the given block matches the search text.
nextSelects the next block.
openOpens the search bar.
positionPositions the workspace search field. It is positioned in the opposite corner to the corner the categories/toolbox starts at.
previousSelects the previous block.
searchAndHighlightSearches the workspace for the current search term, highlights matching blocks, and greys non-matching blocks.
setCurrentBlockChanges the currently "selected" block and adds extra highlight.
setSearchPlaceholderSets the placeholder text for the search bar text input.
unhighlightCurrentSelectionRemoves "current selection" highlight from provided block.
unhighlightSearchGroupRemoves highlight from the provided blocks.

Constructors​

Constructor​

new WorkspaceSearch(workspace): WorkspaceSearch;

Defined in: workspace_search.ts:102

Class for workspace search.

Parameters​

ParameterTypeDescription
workspaceWorkspaceSvgThe 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​

ParameterTypeDescription
btnHTMLButtonElementThe button to add the event listener to.
onClickFn() => voidThe 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​

ParameterTypeDescription
onlyClosePopupsbooleanWhether 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​

ParameterTypeDescription
workspace?WorkspaceSvgThe workspace to search.
searchText?stringThe search text.
caseSensitive?booleanWhether 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​

ParameterTypeDescription
currentBlockBlockSvgThe block to highlight.

Returns​

void


highlightSearchGroup()​

protected highlightSearchGroup(blocks?): void;

Defined in: workspace_search.ts:770

Adds highlight to the provided blocks.

Parameters​

ParameterTypeDescription
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​

ParameterTypeDescription
blockBlockSvgThe block to check.
searchTextstringThe search text. Note if the search is case insensitive, this will be passed already converted to lowercase letters.
caseSensitive?booleanWhether 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​

ParameterTypeDescription
metricsUiMetricsThe workspace metrics.
savedPositionsRect[]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​

ParameterTypeDescription
searchTextstringThe search text.
preserveCurrent?booleanWhether 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​

ParameterTypeDescription
indexnumberIndex 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​

ParameterTypeDescription
placeholderTextstringThe placeholder text.

Returns​

void


unhighlightCurrentSelection()​

protected unhighlightCurrentSelection(currentBlock): void;

Defined in: workspace_search.ts:760

Removes "current selection" highlight from provided block.

Parameters​

ParameterTypeDescription
currentBlockBlockSvgThe block to unhighlight.

Returns​

void


unhighlightSearchGroup()​

protected unhighlightSearchGroup(blocks?): void;

Defined in: workspace_search.ts:782

Removes highlight from the provided blocks.

Parameters​

ParameterTypeDescription
blocks?BlockSvg[]The blocks to unhighlight.

Returns​

void