int[] (@NotNull final String content) { int caretPosInSourceFile = content.indexOf(CARET_TAG_PREFIX); int caretEndInSourceFile = content.indexOf(">", caretPosInSourceFile); int caretLength = caretEndInSourceFile - caretPosInSourceFile; int visualColumnOffset = 0; if (caretPosInSourceFile >= 0) { String visualOffsetString = content.substring(caretPosInSourceFile + CARET_TAG_PREFIX.length(), caretEndInSourceFile); if (visualOffsetString.length() > 1) { visualColumnOffset = Integer.parseInt(visualOffsetString.substring(1)); } } int selectionStartInSourceFile = content.indexOf(SELECTION_START_TAG); int selectionEndInSourceFile = content.indexOf(SELECTION_END_TAG); if (selectionStartInSourceFile >= 0) { if (caretPosInSourceFile >= 0) { if (caretPosInSourceFile < selectionStartInSourceFile) { selectionStartInSourceFile -= caretLength; selectionEndInSourceFile -= caretLength; } else { if (caretPosInSourceFile < selectionEndInSourceFile) { caretPosInSourceFile -= SELECTION_START_TAG.length(); } else { caretPosInSourceFile -= SELECTION_START_TAG.length() + SELECTION_END_TAG.length(); } } } selectionEndInSourceFile -= SELECTION_START_TAG.length(); } return new int[]{caretPosInSourceFile, visualColumnOffset, selectionStartInSourceFile, selectionEndInSourceFile}; }