List<LookupElement> (List<? extends LookupElement> items) { String selectedText = InjectedLanguageEditorUtil.getTopLevelEditor(myProcess.getParameters().getEditor()).getSelectionModel().getSelectedText(); List<LookupElement> exactMatches = new SmartList<>(); for (int i = 0; i < items.size(); i++) { LookupElement item = items.get(i); boolean isSuddenLiveTemplate = isSuddenLiveTemplate(item); if (isPrefixItem(item, true) && !isSuddenLiveTemplate || item.getLookupString().equals(selectedText)) { if (item instanceof LiveTemplateLookupElement) { // prefer most recent live template lookup item return Collections.singletonList(item); } exactMatches.add(item); } else if (i == 0 && isSuddenLiveTemplate && items.size() > 1 && !CompletionService.isStartMatch(items.get(1), this)) { return Collections.singletonList(item); } } return exactMatches; }