Fix collectAllIndividualStyles

pull/605/head
X Code 3 years ago
parent 15a86e24cd
commit b39ee617d5
  1. 13
      lib/src/models/documents/nodes/line.dart

@ -383,20 +383,20 @@ class Line extends Container<Leaf?> {
return result;
}
/// Returns each offset in selection with its corresponding styles as a list
List<Tuple2<int, Style>> collectAllIndividualStyles(int offset, int len,
{int beg = 0}) {
/// Returns each node segment's length in selection
/// with its corresponding styles as a list
List<Tuple2<int, Style>> collectAllIndividualStyles(int offset, int len) {
final local = math.min(length - offset, len);
final result = <Tuple2<int, Style>>[];
final data = queryChild(offset, true);
var node = data.node as Leaf?;
if (node != null) {
result.add(Tuple2(beg, node.style));
var pos = node.length - data.offset;
result.add(Tuple2(pos, node.style));
while (!node!.isLast && pos < local) {
node = node.next as Leaf;
result.add(Tuple2(pos + beg, node.style));
result.add(Tuple2(node.length, node.style));
pos += node.length;
}
}
@ -405,8 +405,7 @@ class Line extends Container<Leaf?> {
final remaining = len - local;
if (remaining > 0) {
final rest =
nextLine!.collectAllIndividualStyles(0, remaining, beg: local);
final rest = nextLine!.collectAllIndividualStyles(0, remaining);
result.addAll(rest);
}

Loading…
Cancel
Save