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-shadow
sizes the outer container, and is the div in which I measure selection rects.textarea-annotations
hascolor: transparent
but renders<span>
elements used for highlighting/underlining.textarea-itself
is, obviously, the textarea.
.textarea-shadow
sizes the .textarea-group
, and the other elements are position: absolute
with top/left/bottom/right: 0
.