reduceConsecutiveSameStyleBlocksToOne static method
Implementation
static List<TDataGroup> reduceConsecutiveSameStyleBlocksToOne(List<dynamic /*TDataGroup | BlockGroup[]*/ > groups) {
var newLineOp = DeltaInsertOp.createNewLineOp();
final result = groups.map((elm) {
if (elm is! List) {
if (elm is BlockGroup && elm.ops.isEmpty) {
elm.ops.add(newLineOp);
}
return elm as TDataGroup;
}
final elmList = List.castFrom<dynamic, BlockGroup>(elm);
var groupsLastInd = elmList.length - 1;
elmList[0].ops = flatten(
elmList.mapIndexed((i, g) {
if (g.ops.isEmpty) {
return [newLineOp];
}
return List.from(g.ops)..addAll(i < groupsLastInd ? [newLineOp] : []);
}),
);
return elmList[0];
}).toList();
return result;
}