code: function createRange(el, selection) {
  
    var start = selection.start;
    var end = selection.end;
  
    var range = document.createRange();
  
    var i = iterator(el.firstChild, el);
  
    var next = i.node;
    var isClosing = false;
  
    var count = 0;
    var length;
  
    while (next) {
  
      if (count === start) {
        if (isClosing) {
          range.setStartAfter(next);
        } else {
          range.setStartBefore(next);
        }
      }
  
      if (count === end) {
        if (isClosing) {
          range.setEndAfter(next);
        } else {
          range.setEndBefore(next);
        }
  
        return range;
      }
  
      if (!isClosing) {
        if (
          isBr(next) || (
            next.previousSibling && (
              isDiv(next) ||
              isParagraph(next)
            )
          )
        ) {
          count++;
        }
      }
  
      if (isText(next)) {
  
        length = next.textContent.length;
  
        if (count <= start && count + length > start) {
          range.setStart(next, start - count);
        }
  
        if (count + length > end) {
          range.setEnd(next, end - count);
  
          return range;
        }
  
        count += length;
      }
  
      next = i.next();
      isClosing = i.closingTag;
    }
  
    // out of range
    if (count <= start) {
      if (el.lastChild) {
        range.setStartAfter(el.lastChild);
      } else {
        range.setStart(el, 0);
      }
    }
  
    if (el.lastChild) {
      range.setEndAfter(el.lastChild);
    } else {
      range.setEnd(el, 0);
    }
  
    return range;
  }
docs: helpers ///////////////////////////