diff --git a/idea/src/org/jetbrains/kotlin/idea/editor/KotlinLiteralCopyPasteProcessor.kt b/idea/src/org/jetbrains/kotlin/idea/editor/KotlinLiteralCopyPasteProcessor.kt index 928ca5956e0..3552a149f70 100644 --- a/idea/src/org/jetbrains/kotlin/idea/editor/KotlinLiteralCopyPasteProcessor.kt +++ b/idea/src/org/jetbrains/kotlin/idea/editor/KotlinLiteralCopyPasteProcessor.kt @@ -32,7 +32,6 @@ import org.jetbrains.kotlin.idea.inspections.collections.isCalling import org.jetbrains.kotlin.idea.intentions.callExpression import org.jetbrains.kotlin.lexer.KotlinLexer import org.jetbrains.kotlin.lexer.KtTokens -import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.psi.KtEscapeStringTemplateEntry import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.psi.KtStringTemplateExpression @@ -151,13 +150,15 @@ class KotlinLiteralCopyPasteProcessor : CopyPastePreProcessor { res.toString() } } else { - val indent = if (beginTp.firstChild?.text == "\"\"\"" && - beginTp.getQualifiedExpressionForReceiver()?.callExpression?.isCalling(FqName("kotlin.text.trimIndent")) == true - ) { - begin.parent?.prevSibling?.takeIf { it.text != "\n" }?.text ?: "" - } else { - "" - } + val indent = + if (beginTp.firstChild?.text == "\"\"\"" && + beginTp.getQualifiedExpressionForReceiver()?.callExpression?.calleeExpression?.text == "trimIndent" + ) { + begin.parent?.prevSibling?.takeIf { it.text != "\n" }?.text + } else { + null + } ?: "" + val tripleQuoteRe = Regex("[\"]{3,}") TemplateTokenSequence(text).mapIndexed { index, chunk -> when (chunk) { diff --git a/idea/testData/copyPaste/plainTextLiteral/CustomTrimIndent.expected.kt b/idea/testData/copyPaste/plainTextLiteral/CustomTrimIndent.expected.kt new file mode 100644 index 00000000000..3f49d0eec68 --- /dev/null +++ b/idea/testData/copyPaste/plainTextLiteral/CustomTrimIndent.expected.kt @@ -0,0 +1,11 @@ +fun String.trimIndent() = this + +fun test() = doTest(""" + def foo(a) + a ? 0 : 1 + end +""".trimIndent()) + +fun doTest(rubyCode: String) { + // some code here +} diff --git a/idea/testData/copyPaste/plainTextLiteral/CustomTrimIndent.kt b/idea/testData/copyPaste/plainTextLiteral/CustomTrimIndent.kt new file mode 100644 index 00000000000..3c45dbdc1a6 --- /dev/null +++ b/idea/testData/copyPaste/plainTextLiteral/CustomTrimIndent.kt @@ -0,0 +1,10 @@ +fun String.trimIndent() = this + +fun test() = doTest(""" + +""".trimIndent()) + +fun doTest(rubyCode: String) { + // some code here +} + diff --git a/idea/testData/copyPaste/plainTextLiteral/CustomTrimIndent.txt b/idea/testData/copyPaste/plainTextLiteral/CustomTrimIndent.txt new file mode 100644 index 00000000000..17859595532 --- /dev/null +++ b/idea/testData/copyPaste/plainTextLiteral/CustomTrimIndent.txt @@ -0,0 +1,3 @@ +def foo(a) + a ? 0 : 1 +end \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/conversion/copy/LiteralTextToKotlinCopyPasteTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/conversion/copy/LiteralTextToKotlinCopyPasteTestGenerated.java index f400a8fa6f9..e0695f39165 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/conversion/copy/LiteralTextToKotlinCopyPasteTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/conversion/copy/LiteralTextToKotlinCopyPasteTestGenerated.java @@ -34,6 +34,11 @@ public class LiteralTextToKotlinCopyPasteTestGenerated extends AbstractLiteralTe runTest("idea/testData/copyPaste/plainTextLiteral/BrokenEntries.txt"); } + @TestMetadata("CustomTrimIndent.txt") + public void testCustomTrimIndent() throws Exception { + runTest("idea/testData/copyPaste/plainTextLiteral/CustomTrimIndent.txt"); + } + @TestMetadata("MultiLine.txt") public void testMultiLine() throws Exception { runTest("idea/testData/copyPaste/plainTextLiteral/MultiLine.txt");