ReplaceAPI
Defined in: extensions/search/replace.ts:10
Object with methods useful for performing a search and both highlighting and replacing the matches.
Extends
Section titled “Extends”Properties
Section titled “Properties”container
Section titled “container”
readonlycontainer:HTMLDivElement
Defined in: extensions/search/search.ts:50
Container that all the search results are appended to.
Inherited from
Section titled “Inherited from”matches
Section titled “matches”
readonlymatches: [number,number][]
Defined in: extensions/search/search.ts:54
Array of positions of all the matches.
Inherited from
Section titled “Inherited from”
readonlyregex:RegExp
Defined in: extensions/search/search.ts:52
Current regex used for searching.
Inherited from
Section titled “Inherited from”Methods
Section titled “Methods”closest()
Section titled “closest()”closest():
number
Defined in: extensions/search/replace.ts:16
Index of the closest match.
Returns
Section titled “Returns”number
destroy()
Section titled “destroy()”destroy():
void
Defined in: extensions/search/replace.ts:35
Removes the highlight container from the DOM and all potential event listeners.
Returns
Section titled “Returns”void
next()
Section titled “next()”next():
number
Defined in: extensions/search/replace.ts:12
Index of the match ahead of the cursor.
Returns
Section titled “Returns”number
prev()
Section titled “prev()”prev():
number
Defined in: extensions/search/replace.ts:14
Index of the match behind the cursor.
Returns
Section titled “Returns”number
replace()
Section titled “replace()”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.
Parameters
Section titled “Parameters”replacement
Section titled “replacement”string
Returns
Section titled “Returns”number | undefined
replaceAll()
Section titled “replaceAll()”replaceAll(
replacement,selection?):void
Defined in: extensions/search/replace.ts:33
Replaces all search matches with the specified string.
Parameters
Section titled “Parameters”replacement
Section titled “replacement”string
String to replace all matches with.
selection?
Section titled “selection?”[number, number]
Does nothing. Kept for backwards compatibility.
Returns
Section titled “Returns”void
search()
Section titled “search()”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.
Parameters
Section titled “Parameters”string
String to search for.
caseSensitive?
Section titled “caseSensitive?”boolean
Whether or not the search is case sensetive.
wholeWord?
Section titled “wholeWord?”boolean
Whether or not matches must be surrounded by word boundaries.
useRegExp?
Section titled “useRegExp?”boolean
If true, special characters won’t be escaped when creating the RegExp.
selection?
Section titled “selection?”[number, number]
Boundaries to search between. If excluded, all the code is searched.
filter?
Section titled “filter?”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.
wholeWordBoundry?
Section titled “wholeWordBoundry?”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.
Returns
Section titled “Returns”string | void
An error message if the RegExp was invalid.
Inherited from
Section titled “Inherited from”selectMatch()
Section titled “selectMatch()”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.
Parameters
Section titled “Parameters”number
scrollPadding?
Section titled “scrollPadding?”number
Returns
Section titled “Returns”void
stopSearch()
Section titled “stopSearch()”stopSearch():
void
Defined in: extensions/search/search.ts:56
Removes the search container and all matches.
Returns
Section titled “Returns”void