Skip to content
Document Authoring DA  API Docs v1.10.0
npmGitHub

SearchResult

SearchResult:

Represents a single match found by a search operation.

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.

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+/i
let result = textView.search(searchFor)
while(result) {
const newRange = textView.replace(`${parseFloat(result.text)*2}`,result.range)
result = textView.search(searchFor,newRange)
}

range: Range

The location of the matched text within the document.

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.

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.