diff --git a/java/java-tests/testData/codeInsight/template/postfix/completion/tabCompletionWithTemplatesInAutopopup.java b/java/java-tests/testData/codeInsight/template/postfix/completion/tabCompletionWithTemplatesInAutopopup.java new file mode 100644 index 000000000000..91505affc0d0 --- /dev/null +++ b/java/java-tests/testData/codeInsight/template/postfix/completion/tabCompletionWithTemplatesInAutopopup.java @@ -0,0 +1,9 @@ +public class Foo { + void m() { + new MyClass() + } + + private class MyClass { + public void parents() {} + } +} diff --git a/java/java-tests/testData/codeInsight/template/postfix/completion/tabCompletionWithTemplatesInAutopopup_after.java b/java/java-tests/testData/codeInsight/template/postfix/completion/tabCompletionWithTemplatesInAutopopup_after.java new file mode 100644 index 000000000000..37167a3508e3 --- /dev/null +++ b/java/java-tests/testData/codeInsight/template/postfix/completion/tabCompletionWithTemplatesInAutopopup_after.java @@ -0,0 +1,9 @@ +public class Foo { + void m() { + new MyClass().parents(); + } + + private class MyClass { + public void parents() {} + } +} diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/template/postfix/completion/TemplatesCompletionTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/template/postfix/completion/TemplatesCompletionTest.java index d7009d0d4ad0..39fd2fbd4f8c 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/template/postfix/completion/TemplatesCompletionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/template/postfix/completion/TemplatesCompletionTest.java @@ -143,6 +143,18 @@ public class TemplatesCompletionTest extends CompletionAutoPopupTestCase { type("r"); myFixture.assertPreferredCompletionItems(selectedIndex, ".par", "parents"); } + + public void testTabCompletionWithTemplatesInAutopopup() { + LiveTemplateCompletionContributor.ourShowTemplatesInTests = true; + + configureByFile(); + type("."); + myFixture.assertPreferredCompletionItems(0, "parents"); + + type("\t"); + assertNull(getLookup()); + checkResultByFile(); + } @Override protected String getBasePath() { 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 cbcdb40e6978..9bcf2de2b9dd 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 @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -112,9 +112,9 @@ public abstract class ChooseItemAction extends EditorAction { PsiDocumentManager.getInstance(file.getProject()).commitDocument(editor.getDocument()); final LiveTemplateLookupElement liveTemplateLookup = ContainerUtil.findInstance(lookup.getItems(), LiveTemplateLookupElement.class); - if (liveTemplateLookup == null) { - // Lookup doesn't contain live templates. It means that - // - there are no any live template: + if (liveTemplateLookup == null || !liveTemplateLookup.sudden) { + // Lookup doesn't contain sudden live templates. It means that + // - there are no live template with given key: // in this case we should find live template with appropriate prefix (custom live templates doesn't participate in this action). // - completion provider worked too long: // in this case we should check custom templates that provides completion lookup.