code: @VisibleForTesting
      int updateSelectionIndex(
              int newLength,
              int editActionStart,
              int editActionAddition,
              int maxInputLength) {
          int newPosition, gapsJumped = 0;
  
          boolean skipBack = false;
          if (editActionStart <= 2 && editActionStart + editActionAddition >= 2) {
              gapsJumped = 1;
          }
  
          // editActionAddition can only be 0 if we are deleting,
          // so we need to check whether or not to skip backwards one space
          if (editActionAddition == 0 && editActionStart == 3) {
              skipBack = true;
          }
  
          newPosition = editActionStart + editActionAddition + gapsJumped;
          if (skipBack && newPosition > 0) {
              newPosition--;
          }
          int untruncatedPosition = newPosition <= newLength ? newPosition : newLength;
          return Math.min(maxInputLength, untruncatedPosition);
      }
docs: Updates the selection index based on the current (pre-edit) index, and
  the size change of the number being input.
  
  @param newLength the post-edit length of the string
  @param editActionStart the position in the string at which the edit action starts
  @param editActionAddition the number of new characters going into the string (zero for
  delete)
  @return an index within the string at which to put the cursor