From 01643844e1c823bff2dbea6e7629238be87787ac Mon Sep 17 00:00:00 2001 From: Mikhail Golubev Date: Sun, 16 Dec 2018 17:05:35 +0700 Subject: [PATCH] PY-32918 Handle enter in f-string right before the closing quote in the context where we don't need to insert additional backslashes. --- .../src/com/jetbrains/python/editor/PythonEnterHandler.java | 3 ++- python/testSrc/com/jetbrains/python/PyEditingTest.java | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/python/src/com/jetbrains/python/editor/PythonEnterHandler.java b/python/src/com/jetbrains/python/editor/PythonEnterHandler.java index b765d876b577..b98f4eca2d11 100644 --- a/python/src/com/jetbrains/python/editor/PythonEnterHandler.java +++ b/python/src/com/jetbrains/python/editor/PythonEnterHandler.java @@ -135,7 +135,8 @@ public class PythonEnterHandler extends EnterHandlerDelegateAdapter { if (stringElement != null && (!stringElement.isFormatted() || nodeType == PyTokenTypes.FSTRING_TEXT || // Caret should be right before the opening brace of an f-string fragment - nodeType == PyTokenTypes.FSTRING_FRAGMENT_START)) { + nodeType == PyTokenTypes.FSTRING_FRAGMENT_START || + nodeType == PyTokenTypes.FSTRING_END)) { if (stringElement.isTripleQuoted() || nodeType == PyTokenTypes.DOCSTRING) { return Result.Continue; } diff --git a/python/testSrc/com/jetbrains/python/PyEditingTest.java b/python/testSrc/com/jetbrains/python/PyEditingTest.java index 414608700044..fb05186be24f 100644 --- a/python/testSrc/com/jetbrains/python/PyEditingTest.java +++ b/python/testSrc/com/jetbrains/python/PyEditingTest.java @@ -126,6 +126,12 @@ public class PyEditingTest extends PyTestCase { " f'{42}bar'"); } + // PY-32918 + public void testEnterInFStringRightBeforeClosingQuote() { + doTestEnter("(f'foo{42}bar')", "(f'foo{42}bar'\n" + + " f'')"); + } + public void testOvertypeFromInside() { assertEquals("''", doTestTyping("''", 1, '\'')); }