code: @VisibleForTesting
      int updateSelectionIndex(
              int newLength,
              int editActionStart,
              int editActionAddition) {
          int newPosition, gapsJumped = 0;
          Set<Integer> gapSet = Card.AMERICAN_EXPRESS.equals(mCardBrand)
                  ? SPACE_SET_AMEX
                  : SPACE_SET_COMMON;
          boolean skipBack = false;
          for (Integer gap : gapSet) {
              if (editActionStart <= gap && editActionStart + editActionAddition > gap) {
                  gapsJumped++;
              }
  
              // 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 == gap + 1) {
                  skipBack = true;
              }
          }
  
          newPosition = editActionStart + editActionAddition + gapsJumped;
          if (skipBack && newPosition > 0) {
              newPosition--;
          }
  
          return newPosition <= newLength ? newPosition : newLength;
      }
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