SearchResult
SearchResult:
Represents a single match found by a search operation.
Remarks
Section titled “Remarks”SearchResult is returned by TextView.searchText when a match is found. It contains
both the matched text and a range, allowing you to inspect the match
and perform further operations on it.
The range property can be passed to other methods like TextView.setFormatting,
TextView.setText, or back to TextView.searchText to continue searching
after this match.
When no match is found, searchText returns undefined instead of a SearchResult.
Examples
Section titled “Examples”Find and highlight the first occurrence:
const result = textView.searchText("important");if (result) { console.log(`Found "${result.text}"`); textView.setFormatting({ highlight: "#ffff00" }, result.range);}Double all numbers:
const searchFor = /\d+/ilet result = textView.search(searchFor)
while(result) { const newRange = textView.replace(`${parseFloat(result.text)*2}`,result.range) result = textView.search(searchFor,newRange)}Properties
Section titled “Properties”range:
Range
The location of the matched text within the document.
Remarks
Section titled “Remarks”An opaque Range object identifying where the match was found. This range
can be used with other TextView methods to manipulate the matched text, or passed
back to TextView.searchText to continue searching after this match.
text:
string
The matched text content.
Remarks
Section titled “Remarks”The actual text string that was matched by the search pattern. For string searches, this is identical to the search string. For RegExp searches, this is the text that matched the pattern.