applyMetadataToTextInSelection method
TextDeltas
applyMetadataToTextInSelection({
- required TextMetadata newMetadata,
- required TextDeltas deltas,
- required TextMetadataChange change,
- required TextSelection selection,
inherited
Applies the newMetadata
to the deltas
in the selection
by the change
.
use TextMetadataChange.all
to apply change to more than one metadata field change.
Implementation
TextDeltas applyMetadataToTextInSelection({
required TextMetadata newMetadata,
required TextDeltas deltas,
required TextMetadataChange change,
required TextSelection selection,
}) {
final TextDeltas modifiedDeltas = deltas.copy;
final int start = selection.start;
final int end = selection.end;
for (int i = start; i < end; i++) {
modifiedDeltas[i] = modifiedDeltas[i].copyWith(
metadata: modifiedDeltas[i].metadata?.combineWhatChanged(
change,
newMetadata,
) ??
newMetadata,
);
}
return modifiedDeltas;
}