mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
don't choose template items by space if normally they're not configured to do so
This commit is contained in:
+16
-1
@@ -631,7 +631,7 @@ public interface Test {
|
||||
assert !lookup
|
||||
}
|
||||
|
||||
public void testTemplateSelection() {
|
||||
public void testTemplateSelectionByComma() {
|
||||
myFixture.configureByText("a.java", """
|
||||
class Foo {
|
||||
int ITER = 2;
|
||||
@@ -651,4 +651,19 @@ class Foo {
|
||||
assert myFixture.editor.document.text.contains('iter,')
|
||||
}
|
||||
|
||||
public void testTemplateSelectionBySpace() {
|
||||
myFixture.configureByText("a.java", """
|
||||
class Foo {
|
||||
int ITER = 2;
|
||||
int itea = 2;
|
||||
|
||||
{
|
||||
it<caret>
|
||||
}
|
||||
}
|
||||
""")
|
||||
type 'er '
|
||||
assert myFixture.editor.document.text.contains('iter ')
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+6
-1
@@ -17,6 +17,7 @@ package com.intellij.codeInsight.template.impl;
|
||||
|
||||
import com.intellij.codeInsight.lookup.CharFilter;
|
||||
import com.intellij.codeInsight.lookup.Lookup;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
@@ -24,7 +25,11 @@ import com.intellij.codeInsight.lookup.Lookup;
|
||||
public class LiveTemplateCharFilter extends CharFilter {
|
||||
@Override
|
||||
public Result acceptChar(char c, int prefixLength, Lookup lookup) {
|
||||
if (lookup.getCurrentItem() instanceof LiveTemplateLookupElement && c != ' ') {
|
||||
LookupElement item = lookup.getCurrentItem();
|
||||
if (item instanceof LiveTemplateLookupElement) {
|
||||
if (c == ((LiveTemplateLookupElement)item).getTemplate().getShortcutChar()) {
|
||||
return Result.SELECT_ITEM_AND_FINISH_LOOKUP;
|
||||
}
|
||||
return Result.HIDE_LOOKUP;
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -45,7 +45,7 @@ public class LiveTemplateCompletionContributor extends CompletionContributor {
|
||||
final int offset = parameters.getOffset();
|
||||
if (Registry.is("show.live.templates.in.completion")) {
|
||||
for (final TemplateImpl possible : listApplicableTemplates(file, offset)) {
|
||||
result.addElement(new LiveTemplateLookupElement(possible.getKey(), possible));
|
||||
result.addElement(new LiveTemplateLookupElement(possible));
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -53,7 +53,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(prefix, template));
|
||||
result.addElement(new LiveTemplateLookupElement(template));
|
||||
} else {
|
||||
for (final TemplateImpl possible : listApplicableTemplates(file, offset)) {
|
||||
result.restartCompletionOnPrefixChange(possible.getKey());
|
||||
|
||||
+6
-2
@@ -28,8 +28,8 @@ public class LiveTemplateLookupElement extends LookupElement {
|
||||
private final String myPrefix;
|
||||
private final TemplateImpl myTemplate;
|
||||
|
||||
public LiveTemplateLookupElement(String prefix, TemplateImpl template) {
|
||||
myPrefix = prefix;
|
||||
public LiveTemplateLookupElement(TemplateImpl template) {
|
||||
myPrefix = template.getKey();
|
||||
myTemplate = template;
|
||||
}
|
||||
@NotNull
|
||||
@@ -38,6 +38,10 @@ public class LiveTemplateLookupElement extends LookupElement {
|
||||
return myPrefix;
|
||||
}
|
||||
|
||||
public TemplateImpl getTemplate() {
|
||||
return myTemplate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderElement(LookupElementPresentation presentation) {
|
||||
super.renderElement(presentation);
|
||||
|
||||
Reference in New Issue
Block a user