From 1d8b64073bdf08d57f9d2c56c3b97b7a5e198071 Mon Sep 17 00:00:00 2001 From: "peter.gromov" Date: Thu, 18 Nov 2010 17:40:53 +0300 Subject: [PATCH] don't focus lookup until all variants have been computed --- .../completion/CodeCompletionHandlerBase.java | 9 +++++---- .../completion/CompletionProgressIndicator.java | 11 +++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java index 1f47088981fa..1e2674ce0ddb 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java @@ -234,7 +234,7 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler { } @NotNull - private LookupImpl obtainLookup(Editor editor, CompletionParameters parameters) { + private LookupImpl obtainLookup(Editor editor) { LookupImpl existing = (LookupImpl)LookupManager.getActiveLookup(editor); if (existing != null && existing.isCompletion()) { existing.markReused(); @@ -251,7 +251,7 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler { lookup.setResizable(false); lookup.setForceLightweightPopup(false); } - lookup.setFocused(shouldFocusLookup(parameters)); + lookup.setFocused(!autopopup); return lookup; } @@ -263,7 +263,7 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler { final CompletionParameters parameters = createCompletionParameters(invocationCount, initContext); - final LookupImpl lookup = obtainLookup(editor, parameters); + final LookupImpl lookup = obtainLookup(editor); final Semaphore freezeSemaphore = new Semaphore(); freezeSemaphore.down(); @@ -295,7 +295,7 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler { indicator.showLookup(); } - private static AtomicReference startCompletionThread(final CompletionParameters parameters, + private AtomicReference startCompletionThread(final CompletionParameters parameters, final CompletionProgressIndicator indicator, final CompletionInitializationContext initContext) { @@ -316,6 +316,7 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler { ApplicationManager.getApplication().runReadAction(new Runnable() { public void run() { startSemaphore.up(); + indicator.setFocusLookupWhenDone(autopopup && shouldFocusLookup(parameters)); indicator.duringCompletion(initContext); } }); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java index 694da606e8d6..8546122d1bfa 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java @@ -122,6 +122,7 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement } }; private final Semaphore myDuringCompletionSemaphore = new Semaphore(); + private volatile boolean myFocusLookupWhenDone; public CompletionProgressIndicator(final Editor editor, CompletionParameters parameters, CodeCompletionHandlerBase handler, Semaphore freezeSemaphore, final OffsetMap offsetMap, LookupImpl lookup) { @@ -203,6 +204,10 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement myDuringCompletionSemaphore.waitFor(); } + public void setFocusLookupWhenDone(boolean focusLookup) { + myFocusLookupWhenDone = focusLookup; + } + private static int findReplacementOffset(int selectionEndOffset, PsiReference reference) { final List ranges = ReferenceRange.getAbsoluteRanges(reference); for (TextRange range : ranges) { @@ -381,6 +386,9 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement myLookup.show(); } myLookup.refreshUi(); + if (!ApplicationManager.getApplication().isUnitTestMode()) { + LOG.assertTrue(myLookup.isVisible()); + } } final boolean isInsideIdentifier() { @@ -500,6 +508,9 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement myHandler.handleEmptyLookup(getProject(), myEditor, myParameters, CompletionProgressIndicator.this); } } else { + if (myFocusLookupWhenDone) { + myLookup.setFocused(true); + } updateLookup(); }