From 457ad67441d7de29e4b587296da7ca25e0f1dbca Mon Sep 17 00:00:00 2001 From: "Anna.Kozlova" Date: Tue, 27 Sep 2016 14:33:07 +0200 Subject: [PATCH] unwrapped selection: ensure highlighting is set according to the text range (IDEA-161690) --- .../unwrap/UnwrapMethodParameterTest.java | 13 +++++++++++++ .../intellij/codeInsight/unwrap/UnwrapHandler.java | 6 ++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/unwrap/UnwrapMethodParameterTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/unwrap/UnwrapMethodParameterTest.java index 90beb89f0faa..3b1303310284 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/unwrap/UnwrapMethodParameterTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/unwrap/UnwrapMethodParameterTest.java @@ -1,5 +1,7 @@ package com.intellij.codeInsight.unwrap; +import com.intellij.openapi.editor.markup.RangeHighlighter; + public class UnwrapMethodParameterTest extends UnwrapTestCase { public void testBasic() throws Exception { assertOptions("foo(bar());", @@ -69,4 +71,15 @@ public class UnwrapMethodParameterTest extends UnwrapTestCase { assertUnwrapped("int f = foo(bar(\"path\"));", "int f = foo(\"path\");"); } + + public void testHighlightingOfTheExtractedFragment() throws Exception { + assertOptions("foo(bar.str);", + "Unwrap 'bar.str'"); + assertUnwrapped("foo(bar.str);", + "bar.str;"); + final RangeHighlighter[] highlighters = myEditor.getMarkupModel().getAllHighlighters(); + assertSize(1, highlighters); + assertEquals(42, highlighters[0].getStartOffset()); + assertEquals(49, highlighters[0].getEndOffset()); + } } \ No newline at end of file diff --git a/platform/lang-impl/src/com/intellij/codeInsight/unwrap/UnwrapHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/unwrap/UnwrapHandler.java index 4074db563e3d..560c7d638728 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/unwrap/UnwrapHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/unwrap/UnwrapHandler.java @@ -34,6 +34,7 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.popup.*; import com.intellij.openapi.util.Key; import com.intellij.openapi.util.Pair; +import com.intellij.openapi.util.TextRange; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.impl.source.tree.RecursiveTreeElementWalkingVisitor; @@ -216,10 +217,11 @@ public class UnwrapHandler implements CodeInsightActionHandler { private void highlightExtractedElements(final List extractedElements) { for (PsiElement each : extractedElements) { + final TextRange textRange = each.getTextRange(); HighlightManager.getInstance(myProject).addRangeHighlight( myEditor, - each.getTextOffset(), - each.getTextOffset() + each.getTextLength(), + textRange.getStartOffset(), + textRange.getEndOffset(), getTestAttributesForExtract(), false, true,