lib/utils.js
function findChangedIndex(prevValue, newValue) {
  var i = 0,
      j = 0;
  var prevLength = prevValue.length;
  var newLength = newValue.length;

  while (prevValue[i] === newValue[i] && i < prevLength) {
    i++;
  } //check what has been changed from last


  while (prevValue[prevLength - 1 - j] === newValue[newLength - 1 - j] && newLength - j > i && prevLength - j > i) {
    j++;
  }

  return {
    start: i,
    end: prevLength - j
  };
}
function findChangedIndex(prevValue, newValue) {
  var i = 0,
      j = 0;
  var prevLength = prevValue.length;
  var newLength = newValue.length;

  while (prevValue[i] === newValue[i] && i < prevLength) {
    i++;
  } //check what has been changed from last


  while (prevValue[prevLength - 1 - j] === newValue[newLength - 1 - j] && newLength - j > i && prevLength - j > i) {
    j++;
  }

  return {
    start: i,
    end: prevLength - j
  };
}
function findChangedIndex ( prevValue , newValue ) { var i = 0 , j = 0 ; var prevLength = prevValue . length ; var newLength = newValue . length ; while ( prevValue [ i ] === newValue [ i ] && i < prevLength ) { i ++ ; } //check what has been changed from last while ( prevValue [ prevLength - 1 - j ] === newValue [ newLength - 1 - j ] && newLength - j > i && prevLength - j > i ) { j ++ ; } return { start : i , end : prevLength - j } ; }
Given previous value and newValue it returns the index
start - end to which values have changed.
This function makes assumption about only consecutive
characters are changed which is correct assumption for caret input.
Given previous value and newValue it returns the index start - end to which values have changed . This function makes assumption about only consecutive characters are changed which is correct assumption for caret input .