mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-22 14:31:25 +07:00
make live template lookup behavior consistent with the "insert by dot/space/etc" option (IDEA-105285)
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
import java.io.File;
|
||||
|
||||
class Foo {
|
||||
{
|
||||
File file = new File("some.txt");
|
||||
System.out.println("file = " + file.<caret>);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
import java.io.File;
|
||||
|
||||
class Foo {
|
||||
{
|
||||
File file = new File("some.txt");
|
||||
<caret>
|
||||
}
|
||||
}
|
||||
@@ -43,6 +43,7 @@ public class LiveTemplateTest extends LightCodeInsightFixtureTestCase {
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
CodeInsightSettings.instance.COMPLETION_CASE_SENSITIVE = CodeInsightSettings.FIRST_LETTER
|
||||
CodeInsightSettings.instance.SELECT_AUTOPOPUP_SUGGESTIONS_BY_CHARS = false
|
||||
if (state != null) {
|
||||
state.gotoEnd();
|
||||
}
|
||||
@@ -249,6 +250,17 @@ class Foo {
|
||||
assert !state.finished
|
||||
}
|
||||
|
||||
public void testFinishTemplateVariantWithDot() {
|
||||
CodeInsightSettings.instance.SELECT_AUTOPOPUP_SUGGESTIONS_BY_CHARS = true
|
||||
configure();
|
||||
startTemplate("soutv", "output")
|
||||
myFixture.type('fil')
|
||||
assert myFixture.lookupElementStrings == ['file']
|
||||
myFixture.type('.')
|
||||
checkResult()
|
||||
assert !state.finished
|
||||
}
|
||||
|
||||
public void testAllowTypingRandomExpressionsWithLookupOpen() {
|
||||
configure();
|
||||
startTemplate("iter", "iterations")
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.intellij.codeInsight.template.impl;
|
||||
|
||||
import com.intellij.codeInsight.CodeInsightSettings;
|
||||
import com.intellij.codeInsight.lookup.CharFilter;
|
||||
import com.intellij.codeInsight.lookup.Lookup;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
@@ -36,6 +37,9 @@ public class LiveTemplateCharFilter extends CharFilter {
|
||||
}
|
||||
if (item instanceof TemplateExpressionLookupElement) {
|
||||
if (Character.isJavaIdentifierPart(c)) return Result.ADD_TO_PREFIX;
|
||||
if (CodeInsightSettings.getInstance().SELECT_AUTOPOPUP_SUGGESTIONS_BY_CHARS) {
|
||||
return null;
|
||||
}
|
||||
return Result.HIDE_LOOKUP;
|
||||
}
|
||||
|
||||
|
||||
@@ -50,9 +50,9 @@ class TemplateExpressionLookupElement extends LookupElementDecorator<LookupEleme
|
||||
private static InsertionContext createInsertionContext(LookupElement item,
|
||||
PsiFile psiFile,
|
||||
List<? extends LookupElement> elements,
|
||||
Editor editor) {
|
||||
Editor editor, final char completionChar) {
|
||||
final OffsetMap offsetMap = new OffsetMap(editor.getDocument());
|
||||
final InsertionContext context = new InsertionContext(offsetMap, (char)0, elements.toArray(new LookupElement[elements.size()]), psiFile, editor, false);
|
||||
final InsertionContext context = new InsertionContext(offsetMap, completionChar, elements.toArray(new LookupElement[elements.size()]), psiFile, editor, false);
|
||||
context.setTailOffset(editor.getCaretModel().getOffset());
|
||||
offsetMap.addOffset(CompletionInitializationContext.START_OFFSET, context.getTailOffset() - item.getLookupString().length());
|
||||
offsetMap.addOffset(CompletionInitializationContext.SELECTION_END_OFFSET, context.getTailOffset());
|
||||
@@ -60,8 +60,8 @@ class TemplateExpressionLookupElement extends LookupElementDecorator<LookupEleme
|
||||
return context;
|
||||
}
|
||||
|
||||
void handleTemplateInsert(List<? extends LookupElement> elements) {
|
||||
final InsertionContext context = createInsertionContext(this, myState.getPsiFile(), elements, myState.getEditor());
|
||||
void handleTemplateInsert(List<? extends LookupElement> elements, final char completionChar) {
|
||||
final InsertionContext context = createInsertionContext(this, myState.getPsiFile(), elements, myState.getEditor(), completionChar);
|
||||
new WriteCommandAction(context.getProject()) {
|
||||
@Override
|
||||
protected void run(Result result) throws Throwable {
|
||||
|
||||
@@ -17,10 +17,7 @@
|
||||
package com.intellij.codeInsight.template.impl;
|
||||
|
||||
import com.intellij.codeInsight.CodeInsightSettings;
|
||||
import com.intellij.codeInsight.lookup.LookupAdapter;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.codeInsight.lookup.LookupEvent;
|
||||
import com.intellij.codeInsight.lookup.LookupManager;
|
||||
import com.intellij.codeInsight.lookup.*;
|
||||
import com.intellij.codeInsight.lookup.impl.LookupImpl;
|
||||
import com.intellij.codeInsight.template.*;
|
||||
import com.intellij.lang.injection.InjectedLanguageManager;
|
||||
@@ -522,7 +519,7 @@ public class TemplateState implements Disposable {
|
||||
private void insertSingleItem(List<TemplateExpressionLookupElement> lookupItems) {
|
||||
TemplateExpressionLookupElement first = lookupItems.get(0);
|
||||
EditorModificationUtil.insertStringAtCaret(myEditor, first.getLookupString());
|
||||
first.handleTemplateInsert(lookupItems);
|
||||
first.handleTemplateInsert(lookupItems, Lookup.AUTO_INSERT_SELECT_CHAR);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -575,7 +572,7 @@ public class TemplateState implements Disposable {
|
||||
|
||||
LookupElement item = event.getItem();
|
||||
if (item instanceof TemplateExpressionLookupElement) {
|
||||
((TemplateExpressionLookupElement)item).handleTemplateInsert(lookupItems);
|
||||
((TemplateExpressionLookupElement)item).handleTemplateInsert(lookupItems, event.getCompletionChar());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user