inputEditForUtf16Replacement method
Creates the complete byte/point edit for one editor replacement without requiring the caller to flatten or traverse its source rope.
Implementation
TreeSitterInputEdit inputEditForUtf16Replacement(
int startUtf16,
int oldEndUtf16,
String insertedText,
) {
if (oldEndUtf16 < startUtf16) {
throw RangeError('oldEndUtf16 precedes startUtf16');
}
final startByte = byteOffsetAtUtf16(startUtf16);
final oldEndByte = byteOffsetAtUtf16(oldEndUtf16);
final inserted = Uint8List.fromList(utf8.encode(insertedText));
final startPosition = pointAtByte(startByte);
return TreeSitterInputEdit(
startByte: startByte,
oldEndByte: oldEndByte,
newEndByte: startByte + inserted.length,
startPosition: startPosition,
oldEndPosition: pointAtByte(oldEndByte),
newEndPosition: _traverse(startPosition, inserted),
startUtf16: startUtf16,
oldEndUtf16: oldEndUtf16,
newEndUtf16: startUtf16 + insertedText.length,
insertedText: insertedText,
);
}