diff --git a/idea/src/org/jetbrains/kotlin/idea/editor/KotlinLiteralCopyPasteProcessor.kt b/idea/src/org/jetbrains/kotlin/idea/editor/KotlinLiteralCopyPasteProcessor.kt
index c645dc14f8d..a017ba33bdb 100644
--- a/idea/src/org/jetbrains/kotlin/idea/editor/KotlinLiteralCopyPasteProcessor.kt
+++ b/idea/src/org/jetbrains/kotlin/idea/editor/KotlinLiteralCopyPasteProcessor.kt
@@ -177,7 +177,8 @@ private class TemplateTokenSequence(private val inputString: String) : Sequence<
}
else if (this.length > 1 && this[0] == '$') {
val guessedIdentifier = substring(1)
- KotlinLexer().apply { start(guessedIdentifier) }.tokenType == KtTokens.IDENTIFIER
+ val tokenType = KotlinLexer().apply { start(guessedIdentifier) }.tokenType
+ tokenType == KtTokens.IDENTIFIER || tokenType == KtTokens.THIS_KEYWORD
}
else {
false
@@ -190,7 +191,8 @@ private class TemplateTokenSequence(private val inputString: String) : Sequence<
when (lexer.tokenType) {
KtTokens.SHORT_TEMPLATE_ENTRY_START -> {
lexer.advance()
- return if (lexer.tokenType == KtTokens.IDENTIFIER) {
+ val tokenType = lexer.tokenType
+ return if (tokenType == KtTokens.IDENTIFIER || tokenType == KtTokens.THIS_KEYWORD) {
from + lexer.tokenEnd - 1
}
else {
diff --git a/idea/testData/copyPaste/literal/DontEscapeThis.expected.kt b/idea/testData/copyPaste/literal/DontEscapeThis.expected.kt
new file mode 100644
index 00000000000..a1a47a4f6c2
--- /dev/null
+++ b/idea/testData/copyPaste/literal/DontEscapeThis.expected.kt
@@ -0,0 +1,3 @@
+class Bar() {
+ val a = "begin This is $this end"
+}
\ No newline at end of file
diff --git a/idea/testData/copyPaste/literal/DontEscapeThis.kt b/idea/testData/copyPaste/literal/DontEscapeThis.kt
new file mode 100644
index 00000000000..b777e583817
--- /dev/null
+++ b/idea/testData/copyPaste/literal/DontEscapeThis.kt
@@ -0,0 +1,3 @@
+class Foo() {
+ val a = "This is $this"
+}
\ No newline at end of file
diff --git a/idea/testData/copyPaste/literal/DontEscapeThis.to.kt b/idea/testData/copyPaste/literal/DontEscapeThis.to.kt
new file mode 100644
index 00000000000..928d6230e53
--- /dev/null
+++ b/idea/testData/copyPaste/literal/DontEscapeThis.to.kt
@@ -0,0 +1,3 @@
+class Bar() {
+ val a = "begin end"
+}
\ No newline at end of file
diff --git a/idea/tests/org/jetbrains/kotlin/idea/conversion/copy/LiteralKotlinToKotlinCopyPasteTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/conversion/copy/LiteralKotlinToKotlinCopyPasteTestGenerated.java
index 94e1eb75d72..9d59f0147d9 100644
--- a/idea/tests/org/jetbrains/kotlin/idea/conversion/copy/LiteralKotlinToKotlinCopyPasteTestGenerated.java
+++ b/idea/tests/org/jetbrains/kotlin/idea/conversion/copy/LiteralKotlinToKotlinCopyPasteTestGenerated.java
@@ -54,6 +54,12 @@ public class LiteralKotlinToKotlinCopyPasteTestGenerated extends AbstractLiteral
doTest(fileName);
}
+ @TestMetadata("DontEscapeThis.kt")
+ public void testDontEscapeThis() throws Exception {
+ String fileName = KotlinTestUtils.navigationMetadata("idea/testData/copyPaste/literal/DontEscapeThis.kt");
+ doTest(fileName);
+ }
+
@TestMetadata("DontUnescapeLiteralWIthCode.kt")
public void testDontUnescapeLiteralWIthCode() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/copyPaste/literal/DontUnescapeLiteralWIthCode.kt");