split method
Apply inline styles or entity data to the block
@param start
: start of the block
@param end
: end of the block
@param style
: Inline style of the block
@param entity
: Entity type of the block
@param data
: data of the block
@param plugins
: List of plugins
@param depth
: depth of the block
Implementation
List<BaseBlock> split(
{required int start,
required int end,
String? style,
String? entity,
required Map<String, dynamic> data,
required List<BasePlugin> plugins,
int? depth}) {
List<BaseBlock> blocks = [];
if (start <= this.start && end >= this.end) {
blocks = [
BaseBlock(
depth: depth ?? this.depth,
blockType: this.blockType,
start: this.start,
end: this.end,
inlineStyles: this.addStyle(style),
data: this.addData(data),
entityTypes: this.addEntityType(entity),
text: this.text,
)
];
} else if (start > this.start && end >= this.end) {
var first = BaseBlock(
depth: depth ?? this.depth,
blockType: this.blockType,
start: this.start,
end: start,
data: this.addData({}),
inlineStyles: addStyle(null),
entityTypes: this.addEntityType(null),
text: this.text,
);
var middle = BaseBlock(
depth: depth ?? this.depth,
blockType: this.blockType,
start: start,
end: this.end,
data: this.addData(data),
inlineStyles: this.addStyle(style),
entityTypes: this.addEntityType(entity),
text: this.text,
);
blocks = [first, middle];
} else if (start <= this.start && end < this.end) {
var first = BaseBlock(
depth: depth ?? this.depth,
blockType: this.blockType,
start: this.start,
end: end,
data: this.addData(data),
inlineStyles: this.addStyle(style),
entityTypes: this.addEntityType(entity),
text: this.text,
);
var middle = BaseBlock(
depth: depth ?? this.depth,
blockType: this.blockType,
start: end,
end: this.end,
data: this.addData({}),
inlineStyles: this.addStyle(null),
entityTypes: this.addEntityType(null),
text: this.text,
);
blocks = [first, middle];
} else if (start > this.start && end < this.end) {
var first = BaseBlock(
depth: depth ?? this.depth,
blockType: this.blockType,
start: this.start,
end: start,
data: this.addData({}),
inlineStyles: this.addStyle(null),
entityTypes: this.addEntityType(null),
text: this.text,
);
var middle = BaseBlock(
depth: depth ?? this.depth,
blockType: this.blockType,
start: start,
end: end,
data: this.addData(data),
inlineStyles: this.addStyle(style),
entityTypes: this.addEntityType(entity),
text: this.text,
);
var last = BaseBlock(
depth: depth ?? this.depth,
blockType: this.blockType,
start: end,
end: this.end,
data: this.addData({}),
inlineStyles: this.addStyle(null),
entityTypes: this.addEntityType(null),
text: this.text,
);
blocks = [first, middle, last];
}
blocks = blocks.map((e) => this.getBlock(e, plugins)).toList();
return blocks;
}