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 +"""''' + } + }