float (@NotNull ColoredFragment fragment, int index, Font font) { if (StringUtil.isEmpty(fragment.text)) return 0; if (myFragments.get(index) != fragment) { return 0; // assertion? } ColoredFragment nextFragment = index < myFragments.size() - 1 ? myFragments.get(index + 1) : null; FontRenderContext frc = getFontRenderContext(font); if (!SystemInfo.isMacOSCatalina || !fragment.attributes.isSearchMatch() || nextFragment == null || fragment.attributes.getFontStyle() != nextFragment.attributes.getFontStyle()) { return getFragmentWidth(fragment, font, frc); } float first = getFragmentWidth(fragment, font, frc); float second = getFragmentWidth(nextFragment, font, frc); float compound = getFragmentWidth(new ColoredFragment(fragment.text + nextFragment.text, fragment.attributes, this, null), font, frc); //return Math.min(w1, w3 - w2); //return (w1 + (w3 - w2)) / 2; return (first + 2 * (compound - second)) / 3; }