highlights

Marks up ranges of a text component with painter - the background a search draws behind its matches, the wash behind an error span, the squiggle under a misspelling.

The declared ranges are the whole of this property's markup: each time the style runs it replaces the marks the previous run left rather than adding to them, so a range that leaves ranges stops being painted and the component carries the winning declaration from the nested and caller styles. Marks installed outside styles are preserved, and a style that stops setting highlights removes only the marks it installed.

A range is painted as the span between its two offsets, whichever way round they are, clamped to the document the way a selection is; a range beyond the text paints as far as the text goes.

The offsets are the declaration itself, not where a mark starts out: an edit under a mark - the user's typing, or a change to the text the composition declares - leaves the range painted where ranges puts it. A span that should move with the edit is set at its new offsets.

The painter is compared by identity, so one built inline is a new painter on every recomposition and repaints the whole set each time; hoist it into a remember to repaint only when ranges change or the document does.

TextArea(state = source, style = { highlights(matches, matchPainter) })

Parameters

ranges

the spans to mark, as offsets into the document. They are read as the style runs, so a snapshot list the style reads runs it again when the list changes.

painter

draws every one of the marks; a single painter serves the whole set.

See also