mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 21:55:01 +07:00
suppress postfix templates [r=ignatov]
This commit is contained in:
committed by
Sergey Ignatov
parent
3d258b9e25
commit
edb1f6b86f
+2
-1
@@ -33,7 +33,8 @@ import static com.intellij.codeInsight.template.postfix.completion.PostfixTempla
|
||||
class PostfixTemplatesCompletionProvider extends CompletionProvider<CompletionParameters> {
|
||||
@Override
|
||||
protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) {
|
||||
if (!isCompletionEnabled(parameters) || LiveTemplateCompletionContributor.shouldShowAllTemplates()) {
|
||||
if (!isCompletionEnabled(parameters) || LiveTemplateCompletionContributor.shouldShowAllTemplates() ||
|
||||
parameters.getEditor().getCaretModel().getCaretCount() != 1) {
|
||||
/**
|
||||
* disabled or covered with {@link com.intellij.codeInsight.template.impl.LiveTemplateCompletionContributor}
|
||||
*/
|
||||
|
||||
+6
-1
@@ -92,6 +92,11 @@ public class PostfixLiveTemplate extends CustomLiveTemplateBase {
|
||||
return computeTemplateKeyWithoutContextChecking(editor.getDocument().getCharsSequence(), editor.getCaretModel().getOffset());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsMultiCaret() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String computeTemplateKeyWithoutContextChecking(@NotNull CharSequence documentContent, int currentOffset) {
|
||||
int startOffset = currentOffset;
|
||||
@@ -174,7 +179,7 @@ public class PostfixLiveTemplate extends CustomLiveTemplateBase {
|
||||
@Override
|
||||
public Collection<? extends CustomLiveTemplateLookupElement> getLookupElements(@NotNull PsiFile file, @NotNull Editor editor, int offset) {
|
||||
String key = computeTemplateKeyWithoutContextChecking(editor.getDocument().getCharsSequence(), offset);
|
||||
if (key != null) {
|
||||
if (key != null && editor.getCaretModel().getCaretCount() == 1) {
|
||||
Map<String, CustomLiveTemplateLookupElement> result = ContainerUtil.newHashMap();
|
||||
Condition<PostfixTemplate> isApplicationTemplateFunction = createIsApplicationTemplateFunction(key, file, editor);
|
||||
for (Map.Entry<String, PostfixTemplate> entry : myTemplates.entrySet()) {
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
import java.lang.Object;
|
||||
|
||||
public class Foo {
|
||||
void m() {
|
||||
new Object().inst<caret>
|
||||
new Object().inst<caret>
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
import java.lang.Object;
|
||||
|
||||
public class Foo {
|
||||
void m() {
|
||||
new Object().inst<caret>
|
||||
new Object().inst<caret>
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
import java.lang.Object;
|
||||
|
||||
public class Foo {
|
||||
void m() {
|
||||
new Object().<caret>
|
||||
new Object().<caret>
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
class A {
|
||||
Object foo;
|
||||
Object bar;
|
||||
|
||||
public static void main(String[] args) {
|
||||
foo == null<caret>
|
||||
|
||||
bar<caret>
|
||||
|
||||
bar == null<caret>
|
||||
}
|
||||
}
|
||||
-16
@@ -1,16 +0,0 @@
|
||||
class A {
|
||||
Object foo;
|
||||
Object bar;
|
||||
|
||||
public static void main(String[] args) {
|
||||
if (foo == null) {
|
||||
|
||||
}
|
||||
|
||||
bar.if
|
||||
|
||||
if (bar == null) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
class A {
|
||||
Object foo;
|
||||
Object bar;
|
||||
|
||||
public static void main(String[] args) {
|
||||
foo == null<caret>
|
||||
bar == null<caret>
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
class A {
|
||||
Object foo;
|
||||
Object bar;
|
||||
|
||||
public static void main(String[] args) {
|
||||
foo == null.if <caret>
|
||||
bar == null.if <caret>
|
||||
}
|
||||
}
|
||||
+26
-4
@@ -17,6 +17,7 @@ package com.intellij.codeInsight.template.postfix.completion;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.codeInsight.completion.CompletionAutoPopupTestCase;
|
||||
import com.intellij.codeInsight.completion.CompletionType;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.codeInsight.lookup.impl.LookupImpl;
|
||||
import com.intellij.codeInsight.template.impl.LiveTemplateCompletionContributor;
|
||||
@@ -27,10 +28,18 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class TemplatesCompletionTest extends CompletionAutoPopupTestCase {
|
||||
private boolean shotTemplatesInTestsOldValue;
|
||||
|
||||
@Override
|
||||
public void setUp() {
|
||||
super.setUp();
|
||||
shotTemplatesInTestsOldValue = LiveTemplateCompletionContributor.ourShowTemplatesInTests;
|
||||
LiveTemplateCompletionContributor.ourShowTemplatesInTests = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tearDown() throws Exception {
|
||||
LiveTemplateCompletionContributor.ourShowTemplatesInTests = false;
|
||||
LiveTemplateCompletionContributor.ourShowTemplatesInTests = shotTemplatesInTestsOldValue;
|
||||
|
||||
PostfixTemplatesSettings settings = PostfixTemplatesSettings.getInstance();
|
||||
assertNotNull(settings);
|
||||
@@ -95,6 +104,17 @@ public class TemplatesCompletionTest extends CompletionAutoPopupTestCase {
|
||||
doAutoPopupTest("instanceof", null);
|
||||
}
|
||||
|
||||
public void testDoNotShowTemplateInMultiCaretMode() {
|
||||
doAutoPopupTest("instanceof", null);
|
||||
}
|
||||
|
||||
public void testDoNotCompleteTemplateInMultiCaretMode() {
|
||||
LiveTemplateCompletionContributor.ourShowTemplatesInTests = true;
|
||||
configureByFile();
|
||||
assertEmpty(myFixture.complete(CompletionType.BASIC));
|
||||
checkResultByFile();
|
||||
}
|
||||
|
||||
public void testShowTemplateOnDoubleLiteral() {
|
||||
doAutoPopupTest("switch", SwitchStatementPostfixTemplate.class);
|
||||
}
|
||||
@@ -146,7 +166,7 @@ public class TemplatesCompletionTest extends CompletionAutoPopupTestCase {
|
||||
|
||||
public void testTabCompletionWithTemplatesInAutopopup() {
|
||||
LiveTemplateCompletionContributor.ourShowTemplatesInTests = true;
|
||||
|
||||
|
||||
configureByFile();
|
||||
type(".");
|
||||
myFixture.assertPreferredCompletionItems(0, "parents");
|
||||
@@ -156,8 +176,10 @@ public class TemplatesCompletionTest extends CompletionAutoPopupTestCase {
|
||||
checkResultByFile();
|
||||
}
|
||||
|
||||
public void testMultiCaret() {
|
||||
doCompleteTest(".if", '\t');
|
||||
public void testShouldNotExpandInMultiCaretMode() {
|
||||
configureByFile();
|
||||
type(".if\t");
|
||||
checkResultByFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+5
-1
@@ -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.
|
||||
@@ -45,4 +45,8 @@ abstract public class CustomLiveTemplateBase implements CustomLiveTemplate {
|
||||
public String computeTemplateKeyWithoutContextChecking(@NotNull CustomTemplateCallback callback) {
|
||||
return computeTemplateKey(callback);
|
||||
}
|
||||
|
||||
public boolean supportsMultiCaret() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -281,6 +281,9 @@ public class TemplateManagerImpl extends TemplateManager implements ProjectCompo
|
||||
|
||||
for (final CustomLiveTemplate customLiveTemplate : CustomLiveTemplate.EP_NAME.getExtensions()) {
|
||||
if (shortcutChar == customLiveTemplate.getShortcut()) {
|
||||
if (editor.getCaretModel().getCaretCount() > 1 && supportsMultiCaretMode(customLiveTemplate)) {
|
||||
continue;
|
||||
}
|
||||
if (isApplicable(customLiveTemplate, editor, file)) {
|
||||
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
|
||||
final CustomTemplateCallback callback = new CustomTemplateCallback(editor, file, false);
|
||||
@@ -304,6 +307,10 @@ public class TemplateManagerImpl extends TemplateManager implements ProjectCompo
|
||||
return startNonCustomTemplates(template2argument, editor, processor);
|
||||
}
|
||||
|
||||
private static boolean supportsMultiCaretMode(CustomLiveTemplate customLiveTemplate) {
|
||||
return customLiveTemplate instanceof CustomLiveTemplateBase && !((CustomLiveTemplateBase)customLiveTemplate).supportsMultiCaret();
|
||||
}
|
||||
|
||||
public static boolean isApplicable(CustomLiveTemplate customLiveTemplate, Editor editor, PsiFile file) {
|
||||
int caretOffset = editor.getCaretModel().getOffset();
|
||||
return customLiveTemplate.isApplicable(file, caretOffset > 0 ? caretOffset - 1 : 0, false);
|
||||
|
||||
Reference in New Issue
Block a user