code: function calculateUpdate(currentSelection, currentValue, newValue) {
  
    var currentCursor = currentSelection.start,
        newCursor = currentCursor,
        diff = newValue.length - currentValue.length,
        idx;
  
    var lengthDelta = newValue.length - currentValue.length;
  
    var currentTail = currentValue.substring(currentCursor);
  
    // check if we can remove common ending from the equation
    // to be able to properly detect a selection change for
    // the following scenarios:
    //
    //  * (AAATTT|TF) => (AAAT|TF)
    //  * (AAAT|TF) =>  (AAATTT|TF)
    //
    if (newValue.lastIndexOf(currentTail) === newValue.length - currentTail.length) {
      currentValue = currentValue.substring(0, currentValue.length - currentTail.length);
      newValue = newValue.substring(0, newValue.length - currentTail.length);
    }
  
    // diff
    var diff = createDiff(currentValue, newValue);
  
    if (diff) {
      if (diff.type === 'remove') {
        newCursor = diff.newStart;
      } else {
        newCursor = diff.newEnd;
      }
    }
  
    return range(newCursor);
  }
docs: Calculate the selection update for the given
  current and new input values.
  
  @param {Object} currentSelection as {start, end}
  @param {String} currentValue
  @param {String} newValue
  
  @return {Object} newSelection as {start, end}