Skip to content

ReplaceAPI

Defined in: extensions/search/replace.ts:10

Object with methods useful for performing a search and both highlighting and replacing the matches.

readonly container: HTMLDivElement

Defined in: extensions/search/search.ts:50

Container that all the search results are appended to.

SearchAPI.container


readonly matches: [number, number][]

Defined in: extensions/search/search.ts:54

Array of positions of all the matches.

SearchAPI.matches


readonly regex: RegExp

Defined in: extensions/search/search.ts:52

Current regex used for searching.

SearchAPI.regex

closest(): number

Defined in: extensions/search/replace.ts:16

Index of the closest match.

number


destroy(): void

Defined in: extensions/search/replace.ts:35

Removes the highlight container from the DOM and all potential event listeners.

void


next(): number

Defined in: extensions/search/replace.ts:12

Index of the match ahead of the cursor.

number


prev(): number

Defined in: extensions/search/replace.ts:14

Index of the match behind the cursor.

number


replace(replacement): number | undefined

Defined in: extensions/search/replace.ts:27

If a match is selected and it’s different to the provided string, it’s replaced, else the index of the closest match is returned. If there’s no selected match, the index of the closest match is returned.

string

number | undefined


replaceAll(replacement, selection?): void

Defined in: extensions/search/replace.ts:33

Replaces all search matches with the specified string.

string

String to replace all matches with.

[number, number]

Does nothing. Kept for backwards compatibility.

void


search(str, caseSensitive?, wholeWord?, useRegExp?, selection?, filter?, wholeWordBoundry?): string | void

Defined in: extensions/search/search.ts:40

Unhides the search container and highlights all matches of the specified string in the editor.

string

String to search for.

boolean

Whether or not the search is case sensetive.

boolean

Whether or not matches must be surrounded by word boundaries.

boolean

If true, special characters won’t be escaped when creating the RegExp.

[number, number]

Boundaries to search between. If excluded, all the code is searched.

SearchFilter

A function called for each match with the start and end positions of the match. If it returns false, the match won’t be included.

RegExp

Pattern controlling the behavior of whole word search. Best left undefined unless you know what you’re doing. Does nothing if wholeWord isn’t set to true. Defaults to /[_\p{N}\p{L}]{2}/u.

string | void

An error message if the RegExp was invalid.

SearchAPI.search


selectMatch(index, scrollPadding?): void

Defined in: extensions/search/replace.ts:21

Selects the match with the passed index and scrolls it into view with the specified scroll padding.

number

number

void


stopSearch(): void

Defined in: extensions/search/search.ts:56

Removes the search container and all matches.

void

SearchAPI.stopSearch