insert(index, text, attributes) {
    if (text.length <= 0) {
      return;
    }

    const y = this.doc;

    if (y !== null) {
      transact(y, transaction => {
        const pos = findPosition(transaction, this, index);

        if (!attributes) {
          attributes = {}; // @ts-ignore

          pos.currentAttributes.forEach((v, k) => {
            attributes[k] = v;
          });
        }

        insertText(transaction, this, pos, text, attributes);
      });
    } else {
      /** @type {Array<function>} */
      this._pending.push(() => this.insert(index, text, attributes));
    }
  }
Insert text at a given index.

@param {number} index The index at which to start inserting.
@param {String} text The text to insert at the specified position.
@param {TextAttributes} [attributes] Optionally define some formatting
                                   information to apply on the inserted
                                   Text.
@public