Collection<ItemWrapper> (@NotNull Project project, @NotNull String pattern) { MinusculeMatcher matcher = NameUtil.buildMatcher("*" + pattern).build(); List<ItemWrapper<?>> list = ChooseRunConfigurationPopup.createFlatSettingsList(project); TreeMap<Integer, ItemWrapper> map = new TreeMap<>(Comparator.reverseOrder()); for (ItemWrapper wrapper : list) { String name = wrapper.getText(); FList<TextRange> fragments = matcher.matchingFragments(name); if (fragments != null) { int rest = fragments.isEmpty() ? 0 : name.length() - fragments.get(fragments.size() - 1).getEndOffset(); map.put(matcher.matchingDegree(name, false, fragments) - rest, wrapper); } } return map.values(); }