private void calculateNextChunk() {
// Get the previous anchor for this line
AnchorManager anchorManager = document.getAnchorManager();
if (prevAnchor == null) {
Anchor startSearchAnchor = document.getAnchorManager().createAnchor(
START_SEARCH_ANCHOR_TYPE, line, AnchorManager.IGNORE_LINE_NUMBER, 1);
prevAnchor = document.getAnchorManager().getPreviousAnchor(startSearchAnchor, anchorType);
document.getAnchorManager().removeAnchor(startSearchAnchor);
if (prevAnchor == null) {
return;
}
} else {
// We have hit an anchor on this line already, get the next one.
prevAnchor = anchorManager.getNextAnchor(prevAnchor, anchorType);
}
Anchor nextAnchor = anchorManager.getNextAnchor(prevAnchor, anchorType);
if (nextAnchor != null && nextAnchor.getLine() == line) {
nextChunkLength = nextAnchor.getColumn() - linePosition;
} else {
nextChunkLength = line.getText().length() - linePosition;
}
assert (nextChunkLength >= 0) : "Got a negative chunk length";