mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Completion: avoid using lookup listeners in case their order matters
This commit is contained in:
+6
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -176,6 +176,11 @@ public class CompletionLookupArranger extends LookupArranger {
|
||||
trimToLimit(lookup, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void itemSelected(@Nullable LookupElement lookupItem, char completionChar) {
|
||||
myProcess.itemSelected(lookupItem, completionChar);
|
||||
}
|
||||
|
||||
private void trimToLimit(Lookup lookup, ProcessingContext context) {
|
||||
if (myItems.size() < myLimit) return;
|
||||
|
||||
|
||||
+11
-14
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -107,19 +107,6 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement
|
||||
private final OffsetMap myOffsetMap;
|
||||
private final List<Pair<Integer, ElementPattern<String>>> myRestartingPrefixConditions = ContainerUtil.createLockFreeCopyOnWriteList();
|
||||
private final LookupAdapter myLookupListener = new LookupAdapter() {
|
||||
@Override
|
||||
public void itemSelected(LookupEvent event) {
|
||||
LookupElement item = event.getItem();
|
||||
boolean dispose = item == null;
|
||||
finishCompletionProcess(dispose);
|
||||
if (dispose) return;
|
||||
|
||||
setMergeCommand();
|
||||
|
||||
myHandler.lookupItemSelected(CompletionProgressIndicator.this, item, event.getCompletionChar(), myLookup.getItems());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void lookupCanceled(final LookupEvent event) {
|
||||
finishCompletionProcess(true);
|
||||
@@ -177,6 +164,16 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement
|
||||
}
|
||||
}
|
||||
|
||||
public void itemSelected(@Nullable LookupElement lookupItem, char completionChar) {
|
||||
boolean dispose = lookupItem == null;
|
||||
finishCompletionProcess(dispose);
|
||||
if (dispose) return;
|
||||
|
||||
setMergeCommand();
|
||||
|
||||
myHandler.lookupItemSelected(this, lookupItem, completionChar, myLookup.getItems());
|
||||
}
|
||||
|
||||
public OffsetMap getOffsetMap() {
|
||||
return myOffsetMap;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,6 +23,7 @@ import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -66,6 +67,9 @@ public abstract class LookupArranger {
|
||||
return matcher.prefixMatches(item);
|
||||
}
|
||||
|
||||
public void itemSelected(@Nullable LookupElement lookupItem, char completionChar) {
|
||||
}
|
||||
|
||||
public void prefixChanged(Lookup lookup) {
|
||||
myAdditionalPrefix = ((LookupImpl)lookup).getAdditionalPrefix();
|
||||
rebuildItemCache(lookup);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -122,9 +122,9 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable,
|
||||
private volatile LookupArranger myArranger;
|
||||
private LookupArranger myPresentableArranger;
|
||||
private final Map<LookupElement, PrefixMatcher> myMatchers =
|
||||
ContainerUtil.createConcurrentWeakMap(ContainerUtil.<LookupElement>identityStrategy());
|
||||
ContainerUtil.createConcurrentWeakMap(ContainerUtil.identityStrategy());
|
||||
private final Map<LookupElement, Font> myCustomFonts = ContainerUtil.createConcurrentWeakMap(10, 0.75f, Runtime.getRuntime().availableProcessors(),
|
||||
ContainerUtil.<LookupElement>identityStrategy());
|
||||
ContainerUtil.identityStrategy());
|
||||
private boolean myStartCompletionWhenNothingMatches;
|
||||
boolean myResizePending;
|
||||
private boolean myFinishing;
|
||||
@@ -813,7 +813,7 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable,
|
||||
|
||||
public void fireItemSelected(@Nullable final LookupElement item, char completionChar){
|
||||
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
|
||||
|
||||
myArranger.itemSelected(item, completionChar);
|
||||
if (!myListeners.isEmpty()){
|
||||
LookupEvent event = new LookupEvent(this, item, completionChar);
|
||||
for (LookupListener listener : myListeners) {
|
||||
|
||||
@@ -183,15 +183,15 @@ public class LookupManagerImpl extends LookupManager {
|
||||
|
||||
private void lookupClosed() {
|
||||
ApplicationManager.getApplication().assertIsDispatchThread();
|
||||
|
||||
alarm.cancelAllRequests();
|
||||
LookupImpl lookup = myActiveLookup;
|
||||
if (lookup == null) return;
|
||||
|
||||
LOG.assertTrue(lookup.isLookupDisposed());
|
||||
lookup.removeLookupListener(this);
|
||||
}
|
||||
});
|
||||
Disposer.register(lookup, new Disposable() {
|
||||
@Override
|
||||
public void dispose() {
|
||||
myActiveLookup = null;
|
||||
myActiveLookupEditor = null;
|
||||
lookup.removeLookupListener(this);
|
||||
myPropertyChangeSupport.firePropertyChange(PROP_ACTIVE_LOOKUP, lookup, null);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user