From c1242b0c71f045c28b9b04be324ea3ef43316d3b Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 23 Nov 2011 09:55:10 +0100 Subject: [PATCH] paste the last \n into gstring --- .../StringLiteralCopyPasteProcessor.java | 7 ++++--- .../plugins/groovy/GroovyCopyPasteTest.groovy | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInsight/editorActions/StringLiteralCopyPasteProcessor.java b/java/java-impl/src/com/intellij/codeInsight/editorActions/StringLiteralCopyPasteProcessor.java index 1c0f2fadb351..1f6c01625a0d 100644 --- a/java/java-impl/src/com/intellij/codeInsight/editorActions/StringLiteralCopyPasteProcessor.java +++ b/java/java-impl/src/com/intellij/codeInsight/editorActions/StringLiteralCopyPasteProcessor.java @@ -144,9 +144,10 @@ public class StringLiteralCopyPasteProcessor implements CopyPastePreProcessor { @NonNls String breaker = getLineBreaker(token); final String[] lines = LineTokenizer.tokenize(text.toCharArray(), false, true); for (int i = 0; i < lines.length; i++) { - String line = lines[i]; - buffer.append(escapeCharCharacters(line, token, escapeSlashes)); - if (i != lines.length - 1) buffer.append(breaker); + buffer.append(escapeCharCharacters(lines[i], token, escapeSlashes)); + if (i != lines.length - 1 || "\n".equals(breaker) && text.endsWith("\n")) { + buffer.append(breaker); + } } text = buffer.toString(); } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/GroovyCopyPasteTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/GroovyCopyPasteTest.groovy index e50d513f3a27..068f9efe47d3 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/GroovyCopyPasteTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/GroovyCopyPasteTest.groovy @@ -86,4 +86,18 @@ Foo f''' doTest 'a.txt', 'a\nd', 'def x = "smth"', 'def x = "smtha\\n" +\n "d"' } + public void testGStringEolReplace() throws Exception { + doTest 'a.txt', + '''first +second +''', + '''def x = """ +foo +"""''', + '''def x = """ +first +second +"""''' + } + }