private static List<TextRange> addPreviousComma(PsiElement e,int cursorOffset){
  PsiElement prevSibling=e.getPrevSibling();
  TextRange textRange=e.getTextRange();
  TextRange offsetRange=null;
  if (prevSibling != null) {
    if (prevSibling instanceof PsiWhiteSpace) {
      PsiElement prevCommaSibling=prevSibling.getPrevSibling();
      if (prevCommaSibling != null) {
        ASTNode node=prevCommaSibling.getNode();
        if (node != null) {
          IElementType commaType=node.getElementType();
          if (commaType == PyTokenTypes.COMMA) {
            offsetRange=new TextRange(textRange.getStartOffset() - 2,textRange.getEndOffset());
            if (offsetRange.contains(cursorOffset) && offsetRange.getLength() > 1) {
              return Collections.singletonList(offsetRange);
            }
          }
        }
      }
    }
 else {
      ASTNode node=prevSibling.getNode();
      if (node != null) {
        IElementType commaType=node.getElementType();
        if (commaType == PyTokenTypes.COMMA) {
          offsetRange=new TextRange(textRange.getStartOffset() - 1,textRange.getEndOffset());
        }
      }
    }
    if (offsetRange != null) {
      if (offsetRange.contains(cursorOffset) && offsetRange.getLength() > 1) {
        return Collections.singletonList(offsetRange);
      }
    }
  }
  return Collections.emptyList();
}

private static List < TextRange > addPreviousComma ( PsiElement e , int cursorOffset ) { PsiElement prevSibling = e . getPrevSibling ( ) ; TextRange textRange = e . getTextRange ( ) ; TextRange offsetRange = null ; if ( prevSibling != null ) { if ( prevSibling instanceof PsiWhiteSpace ) { PsiElement prevCommaSibling = prevSibling . getPrevSibling ( ) ; if ( prevCommaSibling != null ) { ASTNode node = prevCommaSibling . getNode ( ) ; if ( node != null ) { IElementType commaType = node . getElementType ( ) ; if ( commaType == PyTokenTypes . COMMA ) { offsetRange = new TextRange ( textRange . getStartOffset ( ) - 2 , textRange . getEndOffset ( ) ) ; if ( offsetRange . contains ( cursorOffset ) && offsetRange . getLength ( ) > 1 ) { return Collections . singletonList ( offsetRange ) ; } } } } } else { ASTNode node = prevSibling . getNode ( ) ; if ( node != null ) { IElementType commaType = node . getElementType ( ) ; if ( commaType == PyTokenTypes . COMMA ) { offsetRange = new TextRange ( textRange . getStartOffset ( ) - 1 , textRange . getEndOffset ( ) ) ; } } } if ( offsetRange != null ) { if ( offsetRange . contains ( cursorOffset ) && offsetRange . getLength ( ) > 1 ) { return Collections . singletonList ( offsetRange ) ; } } } return Collections . emptyList ( ) ; }
adds previous comma and whitespace to result text range
