The DOM structure:
<div className="textarea-group">
<textarea value={value}
onChange={handleChange}
className="textarea-itself" />´
<div className="textarea-annotations">
{valueWithHighlightedSpans}
</div>
<div className="textarea-shadow">{value}</div>
</div>.textarea-shadowsizes the outer container, and is the div in which I measure selection rects.textarea-annotationshascolor: transparentbut renders<span>elements used for highlighting/underlining.textarea-itselfis, obviously, the textarea.
.textarea-shadow sizes the .textarea-group, and the other elements are position: absolute with top/left/bottom/right: 0.