textDiagnosticNavigationIndex function
Implementation
int? textDiagnosticNavigationIndex({
required List<TextDiagnosticRange> diagnostics,
required int cursorOffset,
int? activeIndex,
bool forward = true,
bool wrap = true,
}) {
if (diagnostics.isEmpty) {
return null;
}
final normalizedOffset = cursorOffset < 0 ? 0 : cursorOffset;
final currentIndex =
activeIndex ??
textDiagnosticContainingIndex(
diagnostics: diagnostics,
offset: normalizedOffset,
);
if (forward) {
if (currentIndex != null) {
final nextIndex = currentIndex + 1;
if (nextIndex < diagnostics.length) {
return nextIndex;
}
return wrap ? 0 : null;
}
for (var index = 0; index < diagnostics.length; index++) {
if (diagnostics[index].startOffset > normalizedOffset) {
return index;
}
}
return wrap ? 0 : null;
}
if (currentIndex != null) {
final previousIndex = currentIndex - 1;
if (previousIndex >= 0) {
return previousIndex;
}
return wrap ? diagnostics.length - 1 : null;
}
for (var index = diagnostics.length - 1; index >= 0; index--) {
if (diagnostics[index].startOffset < normalizedOffset) {
return index;
}
}
return wrap ? diagnostics.length - 1 : null;
}