From 35cd1bebe181a27bba7b0e786e0aa02dfb1d6268 Mon Sep 17 00:00:00 2001 From: Ekaterina Tuzova Date: Wed, 19 Jun 2013 18:44:15 +0400 Subject: [PATCH] do not anyhow change text pasted to a string literal fixed PY-9566 pasting code on an indented line inserts that indentation at the end of the line --- .../com/jetbrains/python/editor/PythonCopyPasteProcessor.java | 3 +++ python/testData/copyPaste/PasteToStringLiteral.after.py | 3 +++ python/testData/copyPaste/PasteToStringLiteral.dst.py | 3 +++ python/testData/copyPaste/PasteToStringLiteral.src.py | 2 ++ python/testSrc/com/jetbrains/python/PyCopyPasteTest.java | 4 ++++ 5 files changed, 15 insertions(+) create mode 100644 python/testData/copyPaste/PasteToStringLiteral.after.py create mode 100644 python/testData/copyPaste/PasteToStringLiteral.dst.py create mode 100644 python/testData/copyPaste/PasteToStringLiteral.src.py diff --git a/python/src/com/jetbrains/python/editor/PythonCopyPasteProcessor.java b/python/src/com/jetbrains/python/editor/PythonCopyPasteProcessor.java index e7726f1cc20d..88d5752c59df 100644 --- a/python/src/com/jetbrains/python/editor/PythonCopyPasteProcessor.java +++ b/python/src/com/jetbrains/python/editor/PythonCopyPasteProcessor.java @@ -61,6 +61,9 @@ public class PythonCopyPasteProcessor implements CopyPastePreProcessor { final int lineNumber = document.getLineNumber(caretOffset); final int lineStartOffset = getLineStartSafeOffset(document, lineNumber); + final PsiElement element = file.findElementAt(caretOffset); + if (PsiTreeUtil.getParentOfType(element, PyStringLiteralExpression.class) != null) return text; + text = addLeadingSpaces(text, NOT_INDENT_FILTER, indentSize, indentChar); int firstLineIndent = StringUtil.findFirst(text, NOT_INDENT_FILTER); final String indentText = getIndentText(file, document, caretOffset, lineNumber, firstLineIndent); diff --git a/python/testData/copyPaste/PasteToStringLiteral.after.py b/python/testData/copyPaste/PasteToStringLiteral.after.py new file mode 100644 index 000000000000..e3e8c8d9b86d --- /dev/null +++ b/python/testData/copyPaste/PasteToStringLiteral.after.py @@ -0,0 +1,3 @@ +if True: + s = "foo" + 'foo' \ No newline at end of file diff --git a/python/testData/copyPaste/PasteToStringLiteral.dst.py b/python/testData/copyPaste/PasteToStringLiteral.dst.py new file mode 100644 index 000000000000..00a8b932a3c4 --- /dev/null +++ b/python/testData/copyPaste/PasteToStringLiteral.dst.py @@ -0,0 +1,3 @@ +if True: + s = "foo" + '' \ No newline at end of file diff --git a/python/testData/copyPaste/PasteToStringLiteral.src.py b/python/testData/copyPaste/PasteToStringLiteral.src.py new file mode 100644 index 000000000000..6ab3f5d0a45b --- /dev/null +++ b/python/testData/copyPaste/PasteToStringLiteral.src.py @@ -0,0 +1,2 @@ +if True: + s = "foo" diff --git a/python/testSrc/com/jetbrains/python/PyCopyPasteTest.java b/python/testSrc/com/jetbrains/python/PyCopyPasteTest.java index 2c80ef0f696e..b44c03f519e9 100644 --- a/python/testSrc/com/jetbrains/python/PyCopyPasteTest.java +++ b/python/testSrc/com/jetbrains/python/PyCopyPasteTest.java @@ -309,6 +309,10 @@ public class PyCopyPasteTest extends PyTestCase { doTest(); } + public void testPasteToStringLiteral() { + doTest(); + } + private void doTestTabs() { final CommonCodeStyleSettings.IndentOptions indentOptions = CodeStyleSettingsManager.getSettings(myFixture.getProject()).getIndentOptions(PythonFileType.INSTANCE);