diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/JavadocAutoLookupHandler.java b/java/java-impl/src/com/intellij/codeInsight/completion/JavadocAutoLookupHandler.java index 16af213f4ca1..ad38c47ef0a3 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/JavadocAutoLookupHandler.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/JavadocAutoLookupHandler.java @@ -25,7 +25,7 @@ import com.intellij.openapi.editor.Editor; */ public class JavadocAutoLookupHandler extends CodeCompletionHandlerBase { public JavadocAutoLookupHandler() { - super(CompletionType.BASIC, false); + super(CompletionType.BASIC, false, false); } protected void doComplete(final int offset1, final int offset2, final CompletionContext context, final FileCopyPatcher dummyIdentifier, diff --git a/platform/lang-impl/src/com/intellij/codeInsight/AutoPopupController.java b/platform/lang-impl/src/com/intellij/codeInsight/AutoPopupController.java index 4e6ef51bcb51..648793698671 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/AutoPopupController.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/AutoPopupController.java @@ -93,7 +93,7 @@ public class AutoPopupController implements Disposable { PsiDocumentManager.getInstance(myProject).commitAllDocuments(); if (condition != null && !condition.value(editor)) return; - new CodeCompletionHandlerBase(CompletionType.BASIC, false).invoke(myProject, editor, file); + new CodeCompletionHandlerBase(CompletionType.BASIC, false, false).invoke(myProject, editor, file); } }; // invoke later prevents cancelling request by keyPressed from the same action 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 4eb3aa6bc6ef..addc215e5644 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java @@ -75,14 +75,16 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler { private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.completion.CodeCompletionHandlerBase"); private final CompletionType myCompletionType; private final boolean myInvokedExplicitly; + final boolean focusLookup; public CodeCompletionHandlerBase(final CompletionType completionType) { - this(completionType, true); + this(completionType, true, true); } - public CodeCompletionHandlerBase(CompletionType completionType, boolean invokedExplicitly) { + public CodeCompletionHandlerBase(CompletionType completionType, boolean invokedExplicitly, boolean focusLookup) { myCompletionType = completionType; myInvokedExplicitly = invokedExplicitly; + this.focusLookup = focusLookup; } public final void invoke(final Project project, final Editor editor) { 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 b3f0d574d29a..664f4b6d2bab 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java @@ -97,6 +97,7 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement myLookup.setResizable(false); myLookup.setForceLightweightPopup(false); } + myLookup.setFocused(handler.focusLookup); myLookup.addLookupListener(new LookupAdapter() { public void itemSelected(LookupEvent event) { diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/DownHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/DownHandler.java index 02afc23c5396..8fae3722b95c 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/DownHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/DownHandler.java @@ -26,6 +26,11 @@ public class DownHandler extends LookupActionHandler { } protected void executeInLookup(final LookupImpl lookup) { - ListScrollingUtil.moveDown(lookup.getList(), 0); + if (!lookup.isFocused()) { + lookup.setFocused(true); + lookup.getList().setSelectedIndex(0); + } else { + ListScrollingUtil.moveDown(lookup.getList(), 0); + } } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupCellRenderer.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupCellRenderer.java index 451396dab7cc..120bc2fd6690 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupCellRenderer.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupCellRenderer.java @@ -115,6 +115,10 @@ public class LookupCellRenderer implements ListCellRenderer { boolean isSelected, boolean hasFocus) { + if (!myLookup.isFocused()) { + isSelected = false; + } + final LookupElement item = (LookupElement)value; final Color foreground = isSelected ? SELECTED_FOREGROUND_COLOR : FOREGROUND_COLOR; final Color background = getItemBackground(list, index, isSelected); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java index 2aafb28329f8..b3f6ac73c93b 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java @@ -100,6 +100,7 @@ public class LookupImpl extends LightweightHint implements Lookup, Disposable { private boolean myHidden = false; private LookupElement myPreselectedItem = EMPTY_LOOKUP_ITEM; private boolean myDirty; + private boolean myFocused; private String myAdditionalPrefix = ""; private final AsyncProcessIcon myProcessIcon; private volatile boolean myCalculating; @@ -147,6 +148,14 @@ public class LookupImpl extends LightweightHint implements Lookup, Disposable { updateListHeight(model); } + public boolean isFocused() { + return myFocused; + } + + public void setFocused(boolean focused) { + myFocused = focused; + } + public AsyncProcessIcon getProcessIcon() { return myProcessIcon; } @@ -583,6 +592,8 @@ public class LookupImpl extends LightweightHint implements Lookup, Disposable { myList.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e){ + setFocused(true); + final Point point = e.getPoint(); final int i = myList.locationToIndex(point); if (i >= 0) { diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/PageDownHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/PageDownHandler.java index aa4729eb7994..6adf8932cde4 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/PageDownHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/PageDownHandler.java @@ -25,6 +25,8 @@ public class PageDownHandler extends LookupActionHandler { } protected void executeInLookup(final LookupImpl lookup) { + if (!lookup.isFocused()) return; + ListScrollingUtil.movePageDown(lookup.getList()); } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/PageUpHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/PageUpHandler.java index c68e843f418c..9f0b6a9d9fec 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/PageUpHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/PageUpHandler.java @@ -25,6 +25,8 @@ public class PageUpHandler extends LookupActionHandler { } protected void executeInLookup(final LookupImpl lookup) { + if (!lookup.isFocused()) return; + ListScrollingUtil.movePageUp(lookup.getList()); } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/ShowLookupActionsHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/ShowLookupActionsHandler.java index 59adc8f75af3..3851dececf07 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/ShowLookupActionsHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/ShowLookupActionsHandler.java @@ -39,6 +39,8 @@ public class ShowLookupActionsHandler extends LookupActionHandler { } protected void executeInLookup(final LookupImpl lookup) { + if (!lookup.isFocused()) return; + final LookupElement element = lookup.getCurrentItem(); if (element == null) { return; diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/TypedHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/TypedHandler.java index 3e524940419e..4cf746cb1e83 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/TypedHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/TypedHandler.java @@ -64,7 +64,7 @@ public class TypedHandler implements TypedActionHandler { return; } - if (result == CharFilter.Result.SELECT_ITEM_AND_FINISH_LOOKUP){ + if (result == CharFilter.Result.SELECT_ITEM_AND_FINISH_LOOKUP && lookup.isFocused()) { LookupElement item = lookup.getCurrentItem(); if (item != null){ FeatureUsageTracker.getInstance().triggerFeatureUsed(CodeCompletionFeatures.EDITING_COMPLETION_FINISH_BY_DOT_ETC); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/UpHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/UpHandler.java index 98c80dee91c8..cb614c605c52 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/UpHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/UpHandler.java @@ -25,6 +25,8 @@ public class UpHandler extends LookupActionHandler { } protected void executeInLookup(final LookupImpl lookup) { + if (!lookup.isFocused()) return; + ListScrollingUtil.moveUp(lookup.getList(), 0); } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/actions/ChooseItemAction.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/actions/ChooseItemAction.java index 6ec2259815b8..030b8a6b4462 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/actions/ChooseItemAction.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/actions/ChooseItemAction.java @@ -21,11 +21,9 @@ import com.intellij.codeInsight.lookup.LookupManager; import com.intellij.codeInsight.lookup.impl.LookupImpl; import com.intellij.openapi.actionSystem.DataContext; import com.intellij.openapi.actionSystem.Presentation; -import com.intellij.openapi.actionSystem.ex.DataConstantsEx; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.actionSystem.EditorAction; import com.intellij.openapi.editor.actionSystem.EditorActionHandler; -import com.intellij.openapi.project.Project; public class ChooseItemAction extends EditorAction { public ChooseItemAction(){ @@ -41,6 +39,6 @@ public class ChooseItemAction extends EditorAction { public void update(Editor editor, Presentation presentation, DataContext dataContext){ LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(editor); - presentation.setEnabled(lookup != null); + presentation.setEnabled(lookup != null && lookup.isFocused()); } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/actions/ChooseItemCompleteStatementAction.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/actions/ChooseItemCompleteStatementAction.java index 1ed57224c8d1..cc61232d1b27 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/actions/ChooseItemCompleteStatementAction.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/actions/ChooseItemCompleteStatementAction.java @@ -43,6 +43,6 @@ public class ChooseItemCompleteStatementAction extends EditorAction { public void update(Editor editor, Presentation presentation, DataContext dataContext){ LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(editor); - presentation.setEnabled(lookup != null); + presentation.setEnabled(lookup != null && lookup.isFocused()); } } \ No newline at end of file diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/actions/ChooseItemReplaceAction.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/actions/ChooseItemReplaceAction.java index d60318d4ae02..108e31c830ac 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/actions/ChooseItemReplaceAction.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/actions/ChooseItemReplaceAction.java @@ -42,6 +42,6 @@ public class ChooseItemReplaceAction extends EditorAction { public void update(Editor editor, Presentation presentation, DataContext dataContext){ LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(editor); - presentation.setEnabled(lookup != null); + presentation.setEnabled(lookup != null && lookup.isFocused()); } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/macro/ClassNameCompleteMacro.java b/platform/lang-impl/src/com/intellij/codeInsight/template/macro/ClassNameCompleteMacro.java index 4bcbba643e96..e6953933964b 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/macro/ClassNameCompleteMacro.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/macro/ClassNameCompleteMacro.java @@ -25,6 +25,6 @@ public class ClassNameCompleteMacro extends BaseCompleteMacro { } CodeInsightActionHandler getCompletionHandler() { - return new CodeCompletionHandlerBase(CompletionType.CLASS_NAME, false); + return new CodeCompletionHandlerBase(CompletionType.CLASS_NAME, false, true); } } \ No newline at end of file diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/macro/CompleteMacro.java b/platform/lang-impl/src/com/intellij/codeInsight/template/macro/CompleteMacro.java index f3e08bce1973..feaf512978d5 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/macro/CompleteMacro.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/macro/CompleteMacro.java @@ -25,6 +25,6 @@ public class CompleteMacro extends BaseCompleteMacro { } CodeInsightActionHandler getCompletionHandler() { - return new CodeCompletionHandlerBase(CompletionType.BASIC, false); + return new CodeCompletionHandlerBase(CompletionType.BASIC, false, true); } } \ No newline at end of file diff --git a/xml/impl/src/com/intellij/codeInsight/completion/XmlAutoLookupHandler.java b/xml/impl/src/com/intellij/codeInsight/completion/XmlAutoLookupHandler.java index afb5e64349ad..90766757a1ee 100644 --- a/xml/impl/src/com/intellij/codeInsight/completion/XmlAutoLookupHandler.java +++ b/xml/impl/src/com/intellij/codeInsight/completion/XmlAutoLookupHandler.java @@ -32,7 +32,7 @@ import com.intellij.xml.util.XmlUtil; */ public class XmlAutoLookupHandler extends CodeCompletionHandlerBase { public XmlAutoLookupHandler() { - super(CompletionType.BASIC, false); + super(CompletionType.BASIC, false, false); } protected void doComplete(final int offset1, final int offset2, final CompletionContext context, final FileCopyPatcher dummyIdentifier, Editor editor,