mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
don't insert pair ) when choosing a lookup item by ( before an identifier
This commit is contained in:
+5
@@ -0,0 +1,5 @@
|
||||
class Foo {
|
||||
{
|
||||
toS<caret>xxx
|
||||
}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
class Foo {
|
||||
{
|
||||
toString(<caret>xxx
|
||||
}
|
||||
}
|
||||
+6
@@ -1264,4 +1264,10 @@ public class ListUtils {
|
||||
checkResult()
|
||||
}
|
||||
|
||||
public void testNoClosingWhenChoosingWithParenBeforeIdentifier() {
|
||||
configure()
|
||||
myFixture.type '('
|
||||
checkResult()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+15
-7
@@ -15,12 +15,12 @@
|
||||
*/
|
||||
package com.intellij.codeInsight.completion.util;
|
||||
|
||||
import com.intellij.codeInsight.TailType;
|
||||
import com.intellij.codeInsight.completion.InsertHandler;
|
||||
import com.intellij.codeInsight.completion.InsertionContext;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiWhiteSpace;
|
||||
@@ -58,22 +58,22 @@ public abstract class ParenthesesInsertHandler<T extends LookupElement> implemen
|
||||
|
||||
private final boolean mySpaceBeforeParentheses;
|
||||
private final boolean mySpaceBetweenParentheses;
|
||||
private final boolean myInsertRightParenthesis;
|
||||
private final boolean myMayInsertRightParenthesis;
|
||||
private final boolean myAllowParametersOnNextLine;
|
||||
|
||||
protected ParenthesesInsertHandler(final boolean spaceBeforeParentheses,
|
||||
final boolean spaceBetweenParentheses,
|
||||
final boolean insertRightParenthesis) {
|
||||
this(spaceBeforeParentheses, spaceBetweenParentheses, insertRightParenthesis, false);
|
||||
final boolean mayInsertRightParenthesis) {
|
||||
this(spaceBeforeParentheses, spaceBetweenParentheses, mayInsertRightParenthesis, false);
|
||||
}
|
||||
|
||||
protected ParenthesesInsertHandler(boolean spaceBeforeParentheses,
|
||||
boolean spaceBetweenParentheses,
|
||||
boolean insertRightParenthesis,
|
||||
boolean mayInsertRightParenthesis,
|
||||
boolean allowParametersOnNextLine) {
|
||||
mySpaceBeforeParentheses = spaceBeforeParentheses;
|
||||
mySpaceBetweenParentheses = spaceBetweenParentheses;
|
||||
myInsertRightParenthesis = insertRightParenthesis;
|
||||
myMayInsertRightParenthesis = mayInsertRightParenthesis;
|
||||
myAllowParametersOnNextLine = allowParametersOnNextLine;
|
||||
}
|
||||
|
||||
@@ -138,7 +138,15 @@ public abstract class ParenthesesInsertHandler<T extends LookupElement> implemen
|
||||
editor.getCaretModel().moveToOffset(context.getTailOffset());
|
||||
}
|
||||
|
||||
if (!myInsertRightParenthesis) return;
|
||||
if (!myMayInsertRightParenthesis) return;
|
||||
|
||||
if (context.getCompletionChar() == '(') {
|
||||
//todo use BraceMatchingUtil.isPairedBracesAllowedBeforeTypeInFileType
|
||||
int tail = context.getTailOffset();
|
||||
if (tail < document.getTextLength() && StringUtil.isJavaIdentifierPart(document.getCharsSequence().charAt(tail))) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
document.insertString(context.getTailOffset(), getSpace(mySpaceBetweenParentheses) + ")");
|
||||
if (!putCaretInside) {
|
||||
|
||||
Reference in New Issue
Block a user