int (int x) { float curX = myIpad.left; //added even if no icon, see com.intellij.ui.SimpleColoredComponent.doPaintText if (myBorder != null) { curX += myBorder.getBorderInsets(this).left; } curX += getInsets().left; if (myIcon != null && !myIconOnTheRight) { final int iconRight = myIcon.getIconWidth() + myIconTextGap; if (x < iconRight) { return FRAGMENT_ICON; } curX += iconRight; } Font font = getBaseFont(); int baseSize = font.getSize(); boolean wasSmaller = false; synchronized (myFragments) { curX += computeTextAlignShift(); for (int i = 0; i < myFragments.size(); i++) { ColoredFragment fragment = myFragments.get(i); SimpleTextAttributes attributes = fragment.attributes; boolean isSmaller = attributes.isSmaller(); if (font.getStyle() != attributes.getFontStyle() || isSmaller != wasSmaller) { // derive font only if it is necessary font = deriveFont(font, attributes.getFontStyle(), isSmaller ? UIUtil.getFontSize(UIUtil.FontSize.SMALL) : baseSize); } wasSmaller = isSmaller; float curWidth = computeStringWidth(fragment, i, font); if (x >= curX && x < curX + curWidth) { return i; } curX += curWidth; final int fragmentPadding = fragment.padding; if (fragmentPadding > 0 && curX < fragmentPadding) { curX = fragmentPadding; } } } if (myIcon != null && myIconOnTheRight) { curX += myIconTextGap + myIpad.left; if (x >= curX && x < curX + myIcon.getIconWidth()) { return FRAGMENT_ICON; } } return -1; }