From e2d7ea5f4f3bbf39835c5ec0bc6264fa617e4708 Mon Sep 17 00:00:00 2001 From: Dmitry Batrak Date: Mon, 6 Feb 2017 16:24:30 +0300 Subject: [PATCH] IDEA-167667 Unexpected substitution during block selection paste in java --- .../editorActions/CopyPasteReferenceProcessor.java | 10 ++++++---- .../editorActions/CopyPasteFoldingProcessor.java | 10 +++++++--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInsight/editorActions/CopyPasteReferenceProcessor.java b/java/java-impl/src/com/intellij/codeInsight/editorActions/CopyPasteReferenceProcessor.java index 66056e42797b..a05a9999cdc1 100644 --- a/java/java-impl/src/com/intellij/codeInsight/editorActions/CopyPasteReferenceProcessor.java +++ b/java/java-impl/src/com/intellij/codeInsight/editorActions/CopyPasteReferenceProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -57,11 +57,13 @@ public abstract class CopyPasteReferenceProcessor exten } final ArrayList array = new ArrayList<>(); + int refOffset = 0; // this is an offset delta for conversion from absolute offset to an offset inside clipboard contents for (int j = 0; j < startOffsets.length; j++) { - final int startOffset = startOffsets[j]; - for (final PsiElement element : CollectHighlightsUtil.getElementsInRange(file, startOffset, endOffsets[j])) { - addReferenceData(file, startOffset, element, array); + refOffset += startOffsets[j]; + for (final PsiElement element : CollectHighlightsUtil.getElementsInRange(file, startOffsets[j], endOffsets[j])) { + addReferenceData(file, refOffset, element, array); } + refOffset -= endOffsets[j] + 1; // 1 accounts for line break inserted between contents corresponding to different carets } if (array.isEmpty()) { diff --git a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/CopyPasteFoldingProcessor.java b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/CopyPasteFoldingProcessor.java index 80fa399a5fca..6164efb982a0 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/CopyPasteFoldingProcessor.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/CopyPasteFoldingProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,16 +46,20 @@ public class CopyPasteFoldingProcessor extends CopyPastePostProcessor