TextWithMnemonic (@NotNull @Nls String text, int index) { if (index < 0) return fromPlainText(text); if (index < text.length()) { // try to extract a mnemonic suffix int pos = text.length() - getEllipsisLength(text) - 3; // the length of "(M)" if (pos >= 0 && index == (pos + 1) && text.charAt(pos) == '(' && text.charAt(pos + 2) == ')') { while (pos > 0 && text.charAt(pos - 1) == ' ') pos--; // skip spaces return new TextWithMnemonic(text.substring(0, pos), index, text.substring(pos)); } } return new TextWithMnemonic(text, index, ""); }