text blocks: don't escape paste outside content of text block (IDEA-217353)

GitOrigin-RevId: 7ee24196154f11a34b50d2d95c62f374abe13f14
This commit is contained in:
Bas Leijdekkers
2019-07-31 15:56:10 +02:00
committed by intellij-monorepo-bot
parent 3a73782bb6
commit dca820c744
4 changed files with 17 additions and 3 deletions

View File

@@ -178,11 +178,14 @@ public class StringLiteralCopyPasteProcessor implements CopyPastePreProcessor {
if (elementAtSelectionStart == null) {
return null;
}
if (!isStringLiteral(elementAtSelectionStart) && !isCharLiteral(elementAtSelectionStart) && !isTextBlock(elementAtSelectionStart)) {
final boolean isTextBlock = isTextBlock(elementAtSelectionStart);
if (!isStringLiteral(elementAtSelectionStart) && !isCharLiteral(elementAtSelectionStart) && !isTextBlock) {
return null;
}
if (elementAtSelectionStart.getTextRange().getEndOffset() < selectionEnd) {
final TextRange range = elementAtSelectionStart.getTextRange();
final TextRange textRange = isTextBlock ? new TextRange(range.getStartOffset() + 3, range.getEndOffset() - 2) : range;
if (textRange.getEndOffset() < selectionEnd) {
final PsiElement elementAtSelectionEnd = file.findElementAt(selectionEnd);
if (elementAtSelectionEnd == null) {
return null;
@@ -193,7 +196,6 @@ public class StringLiteralCopyPasteProcessor implements CopyPastePreProcessor {
}
}
final TextRange textRange = elementAtSelectionStart.getTextRange();
if (selectionStart <= textRange.getStartOffset() || selectionEnd >= textRange.getEndOffset()) {
return null;
}

View File

@@ -0,0 +1,4 @@
class C {
String empty = """
"\"";
}

View File

@@ -0,0 +1,4 @@
class C {
String empty = """
"<caret>"";
}

View File

@@ -26,6 +26,10 @@ class JavaTextBlocksHighlightingTest : LightJavaCodeInsightFixtureTestCase() {
doTestPaste("\"\"\"\ntarget\"\"\"".trimIndent())
}
fun testNoEscapeWhenNotInTextBlockContent() {
doTestPaste("\\");
}
private fun doTestPaste(textToPaste: String) {
myFixture.configureByText("plain.txt", "<selection>$textToPaste</selection>")
myFixture.performEditorAction(IdeActions.ACTION_EDITOR_COPY)