FindState

class FindState(val textState: TextEditorState, scope: CoroutineScope)(source)

State management for the Find feature.

Parameters

textState

The TextEditorState to search within

scope

CoroutineScope for handling text change reactions

Constructors

Link copied to clipboard
constructor(textState: TextEditorState, scope: CoroutineScope)

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Whether matches are limited to the selection captured by toggleInSelection. The scope follows edits; if its text is deleted or the document replaced, this turns off. An undo that brings back text the scope covered brings the scope back with it, and turns this back on if the deletion had turned it off.

Link copied to clipboard

Whether query is a regular expression that does not compile; it then finds nothing.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Whether query is a regular expression.

Link copied to clipboard

Whether a match must stand as a whole word.

Functions

Link copied to clipboard

Clear the search - remove all highlights and reset state.

Link copied to clipboard
fun close()

End the find session: remove all highlights and reset the query and results, but keep the selection so the last match found stays selected in the editor.

Link copied to clipboard
fun dispose()

Cancel any ongoing operations. Call this when done with FindState.

Link copied to clipboard
fun findNext()

Navigate to the next match.

Link copied to clipboard

Navigate to the previous match.

Link copied to clipboard
fun goToMatch(index: Int)

Jump to a specific match by index.

Link copied to clipboard
fun replaceAll(replaceText: String): Int

Replace all matches with the given text, each taking the styling at the start of the text it replaces. Matches are found afresh in the current text; where matches overlap, only the first is replaced.

Link copied to clipboard
fun replaceCurrent(replaceText: String): Boolean

Replace the current match with the given text and move to the next match. The replacement takes the styling at the start of the text it replaces.

Link copied to clipboard
fun search(newQuery: String)

Execute a search with the given query. Updates highlights and jumps to the nearest match.

Link copied to clipboard

Toggle case sensitivity and re-run search if there's an active query.

Link copied to clipboard

Limit matches to the current selection, or search the whole document again. While the selection is a match this session selected, or there is none, the user's last own selection is used instead, as long as the only edits since were this session's replacements. Enabling does nothing when there is no such selection.

Link copied to clipboard
fun toggleRegex(enabled: Boolean)

Toggle regular expression matching and re-run search if there's an active query. See isInvalidPattern.

Link copied to clipboard
fun toggleWholeWord(enabled: Boolean)

Toggle whole-word matching and re-run search if there's an active query.