setDeltas method
set the new deltas and reset metadata relative to the new selection/caret position
Implementation
void setDeltas(TextDeltas newDeltas) {
deltas.clear();
deltas.addAll(newDeltas);
if (selection.isCollapsed) resetMetadataOnSelectionCollapsed();
}