// TODO: Optimize this search.
// Seach for reference at position where the cursor would have been if there were
// no text changes.
LineNumberAndColumn oldPosition = positionMigrator.migrateFromNow(line, column);
for (int i = 0; i < cubeReferences.getReferences().size(); i++) {
CodeReference reference = cubeReferences.getReferences().get(i);
if (reference.getReferenceStart().getLineNumber() > oldPosition.lineNumber) {
// We've gone too far, nothing to look further.
break;
}
if (isFilePositionBefore(reference.getReferenceStart(), oldPosition.lineNumber,
oldPosition.column)
&& isFilePositionAfter(reference.getReferenceEnd(), oldPosition.lineNumber,
oldPosition.column)) {
// Migrate old reference to new position after edits.
CodeReference newReference = migrateCubeReference(reference);
if (newReference != null) {
result = NavigableReference.createToFile(newReference);
}
break;
}