mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
don't select autopopup live templates
This commit is contained in:
+3
-3
@@ -66,7 +66,7 @@ class JavaAutoPopupTest extends CompletionAutoPopupTestCase {
|
||||
|
||||
type('er')
|
||||
assertOrderedEquals myFixture.lookupElementStrings, "iter", "iterable"
|
||||
assertEquals 'iter', lookup.currentItem.lookupString
|
||||
assertEquals 'iterable', lookup.currentItem.lookupString
|
||||
assert lookup.focused
|
||||
|
||||
type 'a'
|
||||
@@ -651,7 +651,7 @@ class Foo {
|
||||
assertOrderedEquals myFixture.lookupElementStrings, "iter", "itera"
|
||||
type ','
|
||||
assert !lookup
|
||||
assert myFixture.editor.document.text.contains('iter,')
|
||||
assert myFixture.editor.document.text.contains('itera,')
|
||||
}
|
||||
|
||||
public void testTemplateSelectionBySpace() {
|
||||
@@ -995,7 +995,7 @@ public class UTest {
|
||||
assert 'xxxxx.SYSTEM_EXCEPTION' == ((JavaPsiClassReferenceElement) myFixture.lookupElements[2]).qualifiedName
|
||||
}
|
||||
|
||||
public void testTabShouldPreferLookupsToLiveTemplate() {
|
||||
public void _testTabShouldPreferLookupsToLiveTemplate() {
|
||||
myFixture.configureByText "a.java", """
|
||||
class LiveComplete {
|
||||
public void innerThing() { }
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.intellij.codeInsight.completion.impl.CamelHumpMatcher;
|
||||
import com.intellij.codeInsight.hint.HintManager;
|
||||
import com.intellij.codeInsight.hint.HintManagerImpl;
|
||||
import com.intellij.codeInsight.lookup.*;
|
||||
import com.intellij.codeInsight.template.impl.LiveTemplateLookupElement;
|
||||
import com.intellij.featureStatistics.FeatureUsageTracker;
|
||||
import com.intellij.ide.ui.UISettings;
|
||||
import com.intellij.lang.LangBundle;
|
||||
@@ -453,7 +454,7 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable
|
||||
|
||||
if (!model.isEmpty()) {
|
||||
LookupElement first = model.iterator().next();
|
||||
if (isFocused() && (!isExactPrefixItem(first, true) || mySelectionTouched)) {
|
||||
if (isFocused() && (!isExactPrefixItem(first, true) || mySelectionTouched || shouldSkip(first))) {
|
||||
restoreSelection(oldSelected, hasPreselected, oldInvariant, snapshot.second);
|
||||
}
|
||||
else {
|
||||
@@ -462,6 +463,10 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean shouldSkip(LookupElement element) {
|
||||
return element instanceof LiveTemplateLookupElement && ((LiveTemplateLookupElement)element).sudden;
|
||||
}
|
||||
|
||||
private boolean isSelectionVisible() {
|
||||
return myList.getFirstVisibleIndex() <= myList.getSelectedIndex() && myList.getSelectedIndex() <= myList.getLastVisibleIndex();
|
||||
}
|
||||
@@ -1264,7 +1269,7 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable
|
||||
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
LookupElement item = items.get(i);
|
||||
if (isExactPrefixItem(item, true)) {
|
||||
if (isExactPrefixItem(item, true) && !shouldSkip(item)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -68,7 +68,7 @@ public class ListTemplatesHandler implements CodeInsightActionHandler {
|
||||
public static void showTemplatesLookup(final Project project, final Editor editor, String prefix, List<TemplateImpl> matchingTemplates) {
|
||||
List<LookupElement> array = new ArrayList<LookupElement>();
|
||||
for (TemplateImpl template : matchingTemplates) {
|
||||
array.add(new LiveTemplateLookupElement(template));
|
||||
array.add(new LiveTemplateLookupElement(template, false));
|
||||
}
|
||||
LookupElement[] items = array.toArray(new LookupElement[array.size()]);
|
||||
|
||||
|
||||
+13
-3
@@ -16,6 +16,7 @@
|
||||
package com.intellij.codeInsight.template.impl;
|
||||
|
||||
import com.intellij.codeInsight.completion.*;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.codeInsight.template.TemplateContextType;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
@@ -67,7 +68,7 @@ public class LiveTemplateCompletionContributor extends CompletionContributor {
|
||||
final String prefix = result.getPrefixMatcher().getPrefix();
|
||||
final TemplateImpl template = findApplicableTemplate(file, offset, prefix);
|
||||
if (template != null) {
|
||||
result.addElement(new LiveTemplateLookupElement(template));
|
||||
result.addElement(new LiveTemplateLookupElement(template, true));
|
||||
}
|
||||
for (final TemplateImpl possible : templates) {
|
||||
result.restartCompletionOnPrefixChange(possible.getKey());
|
||||
@@ -77,11 +78,11 @@ public class LiveTemplateCompletionContributor extends CompletionContributor {
|
||||
});
|
||||
}
|
||||
|
||||
private void ensureTemplatesShown(Ref<Boolean> templatesShown, List<TemplateImpl> templates, CompletionResultSet result) {
|
||||
private static void ensureTemplatesShown(Ref<Boolean> templatesShown, List<TemplateImpl> templates, CompletionResultSet result) {
|
||||
if (!templatesShown.get()) {
|
||||
templatesShown.set(true);
|
||||
for (final TemplateImpl possible : templates) {
|
||||
result.addElement(new LiveTemplateLookupElement(possible));
|
||||
result.addElement(new LiveTemplateLookupElement(possible, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -107,4 +108,13 @@ public class LiveTemplateCompletionContributor extends CompletionContributor {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static class Skipper extends CompletionPreselectSkipper {
|
||||
|
||||
@Override
|
||||
public boolean skipElement(LookupElement element, CompletionLocation location) {
|
||||
return element instanceof LiveTemplateLookupElement && ((LiveTemplateLookupElement)element).sudden;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+17
-2
@@ -21,14 +21,18 @@ import com.intellij.codeInsight.lookup.LookupElementPresentation;
|
||||
import com.intellij.codeInsight.template.TemplateManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
public class LiveTemplateLookupElement extends LookupElement {
|
||||
private final String myPrefix;
|
||||
private final TemplateImpl myTemplate;
|
||||
public final boolean sudden;
|
||||
|
||||
public LiveTemplateLookupElement(TemplateImpl template) {
|
||||
public LiveTemplateLookupElement(TemplateImpl template, boolean sudden) {
|
||||
this.sudden = sudden;
|
||||
myPrefix = template.getKey();
|
||||
myTemplate = template;
|
||||
}
|
||||
@@ -45,7 +49,18 @@ public class LiveTemplateLookupElement extends LookupElement {
|
||||
@Override
|
||||
public void renderElement(LookupElementPresentation presentation) {
|
||||
super.renderElement(presentation);
|
||||
presentation.setTypeText(myTemplate.getDescription());
|
||||
if (sudden) {
|
||||
presentation.setItemTextBold(true);
|
||||
char shortcutChar = myTemplate.getShortcutChar();
|
||||
if (shortcutChar == TemplateSettings.DEFAULT_CHAR) {
|
||||
shortcutChar = TemplateSettings.getInstance().getDefaultShortcutChar();
|
||||
}
|
||||
presentation.setTypeText(" [" + KeyEvent.getKeyText(shortcutChar) + "] ");
|
||||
presentation.setTailText(" (" + myTemplate.getDescription() + ")", true);
|
||||
} else {
|
||||
presentation.setTypeText(myTemplate.getDescription());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -438,6 +438,8 @@
|
||||
<completion.contributor language="any" implementationClass="com.intellij.codeInsight.completion.FilePathCompletionContributor" id="filePath" order="before javaClassName"/>
|
||||
<completion.contributor language="any" implementationClass="com.intellij.codeInsight.template.impl.LiveTemplateCompletionContributor" id="liveTemplates" order="first"/>
|
||||
|
||||
<completion.skip implementation="com.intellij.codeInsight.template.impl.LiveTemplateCompletionContributor$Skipper" id="skipLiveTemplate"/>
|
||||
|
||||
<completion.contributor language="TEXT" implementationClass="com.intellij.openapi.vcs.CommitCompletionContributor" order="first, before liveTemplates"/>
|
||||
|
||||
<applicationService serviceInterface="com.intellij.execution.console.ConsoleFoldingSettings" serviceImplementation="com.intellij.execution.console.ConsoleFoldingSettings"/>
|
||||
|
||||
Reference in New Issue
Block a user