Search in sources :

Example 1 with PrefixMatcher

use of com.intellij.codeInsight.completion.PrefixMatcher in project intellij-community by JetBrains.

the class LookupTypedHandler method completeTillTypedCharOccurrence.

private static boolean completeTillTypedCharOccurrence(char charTyped, LookupImpl lookup, LookupElement item) {
    PrefixMatcher matcher = lookup.itemMatcher(item);
    final String oldPrefix = matcher.getPrefix() + lookup.getAdditionalPrefix();
    PrefixMatcher expanded = matcher.cloneWithPrefix(oldPrefix + charTyped);
    if (expanded.prefixMatches(item)) {
        for (String s : item.getAllLookupStrings()) {
            if (matcher.prefixMatches(s)) {
                int i = -1;
                while (true) {
                    i = s.indexOf(charTyped, i + 1);
                    if (i < 0)
                        break;
                    final String newPrefix = s.substring(0, i + 1);
                    if (expanded.prefixMatches(newPrefix)) {
                        lookup.replacePrefix(oldPrefix, newPrefix);
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
Also used : PrefixMatcher(com.intellij.codeInsight.completion.PrefixMatcher)

Example 2 with PrefixMatcher

use of com.intellij.codeInsight.completion.PrefixMatcher in project intellij-community by JetBrains.

the class LookupArranger method prefixReplaced.

public final void prefixReplaced(Lookup lookup, String newPrefix) {
    //noinspection unchecked
    Map<LookupElement, PrefixMatcher> newMatchers = new LinkedHashMap(EqualityPolicy.IDENTITY);
    for (LookupElement item : myItems) {
        if (item.isValid()) {
            PrefixMatcher matcher = itemMatcher(item).cloneWithPrefix(newPrefix);
            if (matcher.prefixMatches(item)) {
                newMatchers.put(item, matcher);
            }
        }
    }
    myMatchers.clear();
    myMatchers.putAll(newMatchers);
    myItems.clear();
    myItems.addAll(newMatchers.keySet());
    prefixChanged(lookup);
}
Also used : PrefixMatcher(com.intellij.codeInsight.completion.PrefixMatcher) LinkedHashMap(com.intellij.util.containers.hash.LinkedHashMap)

Aggregations

PrefixMatcher (com.intellij.codeInsight.completion.PrefixMatcher)2 LinkedHashMap (com.intellij.util.containers.hash.LinkedHashMap)1