shiftAnnotations method
Shifts all annotations in nodeId that start at or after fromOffset
by delta characters. Used when the user inserts/deletes text
without re-triggering a full spell check.
Implementation
void shiftAnnotations(String nodeId, int fromOffset, int delta) {
final list = _annotations[nodeId];
if (list == null || list.isEmpty) return;
final updated = <SpellAnnotation>[];
for (final ann in list) {
// Annotation entirely before the edit point → unchanged
if (ann.endOffset <= fromOffset) {
updated.add(ann);
continue;
}
// Annotation entirely after the edit point → shift both offsets
if (ann.startOffset >= fromOffset) {
updated.add(SpellAnnotation(
nodeId: ann.nodeId,
fragmentIndex: ann.fragmentIndex,
startOffset: ann.startOffset + delta,
endOffset: ann.endOffset + delta,
suggestions: ann.suggestions,
misspelledWord: ann.misspelledWord,
));
continue;
}
// Annotation overlaps the edit point → invalidate it (clear it)
// A new check will be triggered by the debounce mechanism.
}
if (updated.isEmpty) {
_annotations.remove(nodeId);
} else {
_annotations[nodeId] = updated;
}
}