int (PsiElement startToMove, PsiElement endToMove, CaretModel caretModel, boolean selectionStartAtCaret) { int shift; if (selectionStartAtCaret) { shift = caretModel.getOffset() - startToMove.getTextRange().getStartOffset(); } else { shift = caretModel.getOffset(); if (startToMove != endToMove) { shift += startToMove.getTextLength(); PsiElement tmp = startToMove.getNextSibling(); while (tmp != endToMove && tmp != null) { if (!(tmp instanceof PsiWhiteSpace)) shift += tmp.getTextLength(); tmp = tmp.getNextSibling(); } } shift -= endToMove.getTextOffset(); } return shift; }