private static @ActionText String cutName(@ActionText String name,
                                              @NlsSafe String shortcutText,
                                              JList<?> list,
                                              IconCompOptionalCompPanel<SimpleColoredComponent> panel) {
      if (!list.isShowing() || list.getWidth() <= 0) {
        return StringUtil.first(name, 60, true); // fallback to previous behaviour
      }

      //we cannot cut HTML formatted strings
      if (name.startsWith("<html>")) return name;

      // we have a min size for SE, which is ~40 symbols, don't spend time for trimming, let's use a shortcut
      if (name.length() < 40) return name;

      int freeSpace = calcFreeSpace(list, panel, shortcutText);

      if (freeSpace <= 0) {
        return name;
      }

      SimpleColoredComponent nameComponent = panel.getCenter();
      FontMetrics fm = nameComponent.getFontMetrics(nameComponent.getFont());
      int strWidth = fm.stringWidth(name);
      if (strWidth <= freeSpace) {
        return name;
      }

      int cutSymbolIndex = (int)((((double)freeSpace - fm.stringWidth("...")) / strWidth) * name.length());
      cutSymbolIndex = Integer.max(1, cutSymbolIndex);
      name = name.substring(0, cutSymbolIndex);
      while (fm.stringWidth(name + "...") > freeSpace && name.length() > 1) {
        name = name.substring(0, name.length() - 1);
      }

      return name.trim() + "...";
    }
private static @ActionText String cutName(@ActionText String name,
                                              @NlsSafe String shortcutText,
                                              JList<?> list,
                                              IconCompOptionalCompPanel<SimpleColoredComponent> panel)