insertAfter method
Insert value immediately after the position anchor (null / Dot.origin
= at the very start). Returns the touched block start.
The anchor is a stable position: it works across concurrent edits and even when the anchored element has since been deleted (a tombstone still anchors positions). This is the primary edit entry point for an editor that tracks positions rather than indices.
Implementation
Dot insertAfter(Dot? anchor, T value, Dot dot) {
final leftOrigin = anchor ?? Dot.origin;
final vis = _visibleElems();
final (start, elem) = _place(leftOrigin, value, dot);
// Keep the projection valid: splice right after the anchor's visible
// position; rebuild lazily if the anchor isn't currently visible.
if (leftOrigin.isOrigin) {
vis.insert(0, elem);
} else {
var j = -1;
for (var k = 0; k < vis.length; k++) {
if (vis[k].dot == leftOrigin) {
j = k;
break;
}
}
if (j >= 0) {
vis.insert(j + 1, elem);
} else {
_visibleCache = null;
}
}
return start;
}