diff --git a/python/src/com/jetbrains/python/actions/PyFillParagraphHandler.java b/python/src/com/jetbrains/python/actions/PyFillParagraphHandler.java index bc6e8c94082a..f52815a09d5c 100644 --- a/python/src/com/jetbrains/python/actions/PyFillParagraphHandler.java +++ b/python/src/com/jetbrains/python/actions/PyFillParagraphHandler.java @@ -2,6 +2,7 @@ package com.jetbrains.python.actions; import com.intellij.codeInsight.editorActions.fillParagraph.ParagraphFillHandler; import com.intellij.openapi.util.Pair; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.PsiComment; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; @@ -15,6 +16,8 @@ import com.jetbrains.python.psi.PyStringLiteralExpression; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.List; + /** * User : ktisha */ @@ -25,12 +28,22 @@ public class PyFillParagraphHandler extends ParagraphFillHandler { final PyStringLiteralExpression stringLiteralExpression = PsiTreeUtil.getParentOfType(element, PyStringLiteralExpression.class); if (stringLiteralExpression != null) { + final String text = stringLiteralExpression.getText(); final Pair quotes = - PythonStringUtil.getQuotes(stringLiteralExpression.getText()); + PythonStringUtil.getQuotes(text); final PyDocStringOwner docStringOwner = PsiTreeUtil.getParentOfType(stringLiteralExpression, PyDocStringOwner.class); if (docStringOwner != null && stringLiteralExpression.equals(docStringOwner.getDocStringExpression())) { String indent = getIndent(stringLiteralExpression); - return quotes != null? quotes.getFirst()+ indent : "\"" + indent; + if (quotes != null) { + final List strings = StringUtil.split(text, "\n"); + if (strings.get(0).trim().equals(quotes.getFirst())) { + return quotes.getFirst() + indent; + } + else { + return quotes.getFirst(); + } + } + return "\"" + indent; } else return quotes != null? quotes.getFirst() : "\""; @@ -57,12 +70,22 @@ public class PyFillParagraphHandler extends ParagraphFillHandler { final PyStringLiteralExpression stringLiteralExpression = PsiTreeUtil.getParentOfType(element, PyStringLiteralExpression.class); if (stringLiteralExpression != null) { + final String text = stringLiteralExpression.getText(); final Pair quotes = - PythonStringUtil.getQuotes(stringLiteralExpression.getText()); + PythonStringUtil.getQuotes(text); final PyDocStringOwner docStringOwner = PsiTreeUtil.getParentOfType(stringLiteralExpression, PyDocStringOwner.class); if (docStringOwner != null && stringLiteralExpression.equals(docStringOwner.getDocStringExpression())) { String indent = getIndent(stringLiteralExpression); - return quotes != null? indent + quotes.getSecond() : indent + "\""; + if (quotes != null) { + final List strings = StringUtil.split(text, "\n"); + if (strings.get(strings.size()-1).trim().equals(quotes.getSecond())) { + return indent + quotes.getSecond(); + } + else { + return quotes.getSecond(); + } + } + return indent + "\""; } else return quotes != null? quotes.getSecond() : "\""; diff --git a/python/testData/fillParagraph/prefixPostfix.py b/python/testData/fillParagraph/prefixPostfix.py new file mode 100644 index 000000000000..51ad7c7d07df --- /dev/null +++ b/python/testData/fillParagraph/prefixPostfix.py @@ -0,0 +1,6 @@ +__author__ = 'ktisha' + +def foo(): + """A Map from key to total # of views by that key. This can be expensive to + the big fetch with blackjack and whores, so we generally want to fetch this only for keys that have a large + absolute number of views, a small number of days between views, etc.""" \ No newline at end of file diff --git a/python/testData/fillParagraph/prefixPostfix_after.py b/python/testData/fillParagraph/prefixPostfix_after.py new file mode 100644 index 000000000000..30d2c6f39a4f --- /dev/null +++ b/python/testData/fillParagraph/prefixPostfix_after.py @@ -0,0 +1,6 @@ +__author__ = 'ktisha' + +def foo(): + """A Map from key to total # of views by that key. This can be expensive to the big fetch with blackjack and + whores, so we generally want to fetch this only for keys that have a large absolute number of views, + a small number of days between views, etc. """ \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/PyFillParagraphTest.java b/python/testSrc/com/jetbrains/python/PyFillParagraphTest.java index 768890a2da23..b30b63783056 100644 --- a/python/testSrc/com/jetbrains/python/PyFillParagraphTest.java +++ b/python/testSrc/com/jetbrains/python/PyFillParagraphTest.java @@ -36,6 +36,10 @@ public class PyFillParagraphTest extends PyTestCase { doTest(); } + public void testPrefixPostfix() { + doTest(); + } + private void doTest() { String baseName = "/fillParagraph/" + getTestName(true); myFixture.configureByFile(baseName + ".py");