From aaa238954931e9057aaef147c94f4b24e9fa1042 Mon Sep 17 00:00:00 2001 From: Mikhail Golubev Date: Tue, 13 Sep 2016 02:01:58 +0300 Subject: [PATCH] PY-18972 Automatically close quotes for f-string literals --- .../jetbrains/python/editor/BaseQuoteHandler.java | 12 ++++-------- .../testSrc/com/jetbrains/python/PyEditingTest.java | 8 ++++++++ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/python/src/com/jetbrains/python/editor/BaseQuoteHandler.java b/python/src/com/jetbrains/python/editor/BaseQuoteHandler.java index fb21ab0ec60c..86e89630cc84 100644 --- a/python/src/com/jetbrains/python/editor/BaseQuoteHandler.java +++ b/python/src/com/jetbrains/python/editor/BaseQuoteHandler.java @@ -88,15 +88,11 @@ public class BaseQuoteHandler extends SimpleTokenSetQuoteHandler implements Mult } private static int getLiteralStartOffset(CharSequence text, int start) { - char c = Character.toUpperCase(text.charAt(start)); - if (c == 'U' || c == 'B') { - start++; - c = Character.toUpperCase(text.charAt(start)); + int index = start; + while (index < start + 2 && "URBF".indexOf(Character.toUpperCase(text.charAt(index))) >= 0) { + index++; } - if (c == 'R') { - start++; - } - return start; + return index; } @Override diff --git a/python/testSrc/com/jetbrains/python/PyEditingTest.java b/python/testSrc/com/jetbrains/python/PyEditingTest.java index ea9caf885adb..7a790dd32886 100644 --- a/python/testSrc/com/jetbrains/python/PyEditingTest.java +++ b/python/testSrc/com/jetbrains/python/PyEditingTest.java @@ -87,6 +87,14 @@ public class PyEditingTest extends PyTestCase { assertEquals("'''docstring'''", doTestTyping("'''docstring''", 14, '\'')); } + // PY-18972 + public void testFString() throws Exception { + assertEquals("f''", doTestTyping("f", 1, '\'')); + assertEquals("rf''", doTestTyping("rf", 2, '\'')); + assertEquals("fr''", doTestTyping("fr", 2, '\'')); + assertEquals("fr''''''", doTestTyping("fr''", 4, '\'')); + } + public void testOvertypeFromInside() { assertEquals("''", doTestTyping("''", 1, '\'')); }