nextBlockFromList method
Searches the next block from a given position
.
blockList
is a list of alternative block descriptions.
The search starts at position
. If null the currentPosition is used.
blockStart
: OUT: if not null, the start of the found block is stored here.
blockEnd
: OUT: if not null, the end of the found block is stored here.
endPosition
: OUT: the block end is copied here. If null currentPosition
is taken.
Returns null if search has failed otherwise the block found.
Note: the Block contains an optional name or an intrinsic id to distinct
them from other.
Implementation
Block? nextBlockFromList(List<Block> blockList,
{Position? position,
Position? blockStart,
Position? blockEnd,
Position? endPosition}) {
position ??= currentPosition;
final cursor = Position(0, 0, this);
endPosition ??= currentPosition;
blockStart ??= Position(0, 0, this);
blockEnd ??= Position(0, 0, this);
Block? rc;
var ixLine = position.line;
final stopLine = currentRegion.end.line;
while (rc == null && ixLine < stopLine) {
for (var block in blockList) {
cursor.set(ixLine, startColumnByIndex(ixLine));
if (findBlockEnd(block, startPosition: cursor, blockEnd: blockEnd)) {
rc = block;
blockStart.clone(cursor);
endPosition.clone(blockEnd);
break;
}
}
ixLine++;
}
return rc;
}