int findLineEnd(int offset) { final start = offset.clamp(0, length); final newline = _root.nextNewline(start); return newline ?? length; }