KT-3575, KT-2297 Inserting pair for "${": reverting to use KotlinTypeHandler
(with disabling JetPairMatcher for this case)
This commit is contained in:
committed by
Nikolay Krasko
parent
aeb72922ce
commit
c70a49fab3
@@ -39,8 +39,12 @@ public class JetPairMatcher implements PairedBraceMatcher {
|
||||
|
||||
@Override
|
||||
public boolean isPairedBracesAllowedBeforeType(@NotNull IElementType lbraceType, @Nullable IElementType contextType) {
|
||||
return lbraceType.equals(JetTokens.LONG_TEMPLATE_ENTRY_START)
|
||||
|| JetTokens.WHITE_SPACE_OR_COMMENT_BIT_SET.contains(contextType)
|
||||
if (lbraceType.equals(JetTokens.LONG_TEMPLATE_ENTRY_START)) {
|
||||
// KotlinTypedHandler insert paired brace in this case
|
||||
return false;
|
||||
}
|
||||
|
||||
return JetTokens.WHITE_SPACE_OR_COMMENT_BIT_SET.contains(contextType)
|
||||
|| contextType == JetTokens.SEMICOLON
|
||||
|| contextType == JetTokens.COMMA
|
||||
|| contextType == JetTokens.RPAR
|
||||
|
||||
@@ -57,6 +57,20 @@ public class KotlinTypedHandler extends TypedHandlerDelegate {
|
||||
JetLtGtTypingUtils.handleJetAutoCloseLT(editor);
|
||||
return Result.STOP;
|
||||
}
|
||||
|
||||
if (!(file instanceof JetFile) || !CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET) {
|
||||
return Result.CONTINUE;
|
||||
}
|
||||
if (c == '{') {
|
||||
PsiDocumentManager.getInstance(project).commitAllDocuments();
|
||||
int offset = editor.getCaretModel().getOffset();
|
||||
PsiElement previousElement = file.findElementAt(offset - 1);
|
||||
if (previousElement instanceof LeafPsiElement
|
||||
&& ((LeafPsiElement) previousElement).getElementType() == JetTokens.LONG_TEMPLATE_ENTRY_START) {
|
||||
editor.getDocument().insertString(offset, "}");
|
||||
}
|
||||
return Result.STOP;
|
||||
}
|
||||
return Result.CONTINUE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,18 @@ public class TypedHandlerTest extends LightCodeInsightTestCase {
|
||||
checkResultByText("val x = \"${}\"");
|
||||
}
|
||||
|
||||
public void testTypeStringTemplateStartWithCloseBraceAfter() throws Exception {
|
||||
configureFromFileText("a.kt", "fun foo() { \"$<caret>\" }");
|
||||
EditorTestUtil.performTypingAction(getEditor(), '{');
|
||||
checkResultByText("fun foo() { \"${}\" }");
|
||||
}
|
||||
|
||||
public void testTypeStringTemplateStartBeforeString() throws Exception {
|
||||
configureFromFileText("a.kt", "fun foo() { \"$<caret>something\" }");
|
||||
EditorTestUtil.performTypingAction(getEditor(), '{');
|
||||
checkResultByText("fun foo() { \"${}something\" }");
|
||||
}
|
||||
|
||||
public void testKT3575() throws Exception {
|
||||
configureFromFileText("a.kt", "val x = \"$<caret>]\"");
|
||||
EditorTestUtil.performTypingAction(getEditor(), '{');
|
||||
|
||||
Reference in New Issue
Block a user