private int adjustForward(int pos) {
      if (pos <= offset) return pos;
      if (pos <= offset + oldLength) return offset;
      return pos - oldLength + newLength;
    }
private int adjustForward(int pos)