replaceText method
replace the text at the given index
with the text
.
Implementation
void replaceText(
Node node,
int index,
int length,
String text, {
Attributes? attributes,
}) {
final delta = node.delta;
if (delta == null) {
return;
}
var newAttributes = attributes;
if (index != 0 && attributes == null) {
newAttributes = attributes ?? delta.sliceAttributes(index);
if (newAttributes == null) {
final slicedDelta = delta.slice(index, index + length);
if (slicedDelta.isNotEmpty) {
newAttributes = slicedDelta.first.attributes;
}
}
}
final replace = Delta()
..retain(index)
..delete(length)
..insert(text, attributes: {...newAttributes ?? {}});
addDeltaToComposeMap(node, replace);
afterSelection = Selection.collapsed(
Position(
path: node.path,
offset: index + text.length,
),
);
}