From dff836aa2914a2a790bc1bb7cd80deebb5ba109a Mon Sep 17 00:00:00 2001 From: Mikhail Golubev Date: Fri, 7 Sep 2018 16:14:33 +0300 Subject: [PATCH] PY-31442 Properly complete triple quotes in f-strings --- .../com/jetbrains/python/editor/PythonQuoteHandler.java | 3 ++- python/testSrc/com/jetbrains/python/PyEditingTest.java | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/python/src/com/jetbrains/python/editor/PythonQuoteHandler.java b/python/src/com/jetbrains/python/editor/PythonQuoteHandler.java index d6e9ec334686..56540548697c 100644 --- a/python/src/com/jetbrains/python/editor/PythonQuoteHandler.java +++ b/python/src/com/jetbrains/python/editor/PythonQuoteHandler.java @@ -22,7 +22,8 @@ import com.jetbrains.python.PyTokenTypes; * @author traff */ public class PythonQuoteHandler extends BaseQuoteHandler { - private static final TokenSet APPLICABLE_TOKENS = TokenSet.orSet(PyTokenTypes.STRING_NODES, TokenSet.create(PyTokenTypes.FSTRING_START)); + private static final TokenSet APPLICABLE_TOKENS = TokenSet.orSet(PyTokenTypes.STRING_NODES, + TokenSet.create(PyTokenTypes.FSTRING_START, PyTokenTypes.FSTRING_END)); public PythonQuoteHandler() { super(APPLICABLE_TOKENS, new char[]{'}', ']', ')', ',', ':', ';', ' ', '\t', '\n'}); diff --git a/python/testSrc/com/jetbrains/python/PyEditingTest.java b/python/testSrc/com/jetbrains/python/PyEditingTest.java index 0f77f63e7044..6c948ff79f81 100644 --- a/python/testSrc/com/jetbrains/python/PyEditingTest.java +++ b/python/testSrc/com/jetbrains/python/PyEditingTest.java @@ -96,6 +96,7 @@ public class PyEditingTest extends PyTestCase { assertEquals("rf''", doTestTyping("rf", 2, '\'')); assertEquals("fr''", doTestTyping("fr", 2, '\'')); assertEquals("fr''''''", doTestTyping("fr''", 4, '\'')); + assertEquals("fr''''''", doTestTyping("fr''", 3, "''")); } public void testFStringFragmentBraces() { @@ -505,6 +506,13 @@ public class PyEditingTest extends PyTestCase { return myFixture.getDocument(file).getText(); } + private String doTestTyping(final String text, final int offset, final String characters) { + final PsiFile file = myFixture.configureByText(PythonFileType.INSTANCE, text); + myFixture.getEditor().getCaretModel().moveToOffset(offset); + myFixture.type(characters); + return myFixture.getDocument(file).getText(); + } + private void doTypingTest(final char character) { final String testName = "editing/" + getTestName(true); myFixture.configureByFile(testName + ".py");