unwrapped selection: ensure highlighting is set according to the text range (IDEA-161690)

This commit is contained in:
Anna.Kozlova
2016-09-27 17:21:04 +02:00
parent c661ba9291
commit 457ad67441
2 changed files with 17 additions and 2 deletions
@@ -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(ba<caret>r());",
@@ -69,4 +71,15 @@ public class UnwrapMethodParameterTest extends UnwrapTestCase {
assertUnwrapped("int f = foo(bar(\"path\"<caret>));",
"int f = foo(\"path\"<caret>);");
}
public void testHighlightingOfTheExtractedFragment() throws Exception {
assertOptions("foo(bar.st<caret>r);",
"Unwrap 'bar.str'");
assertUnwrapped("foo(bar.st<caret>r);",
"bar.str;");
final RangeHighlighter[] highlighters = myEditor.getMarkupModel().getAllHighlighters();
assertSize(1, highlighters);
assertEquals(42, highlighters[0].getStartOffset());
assertEquals(49, highlighters[0].getEndOffset());
}
}
@@ -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<PsiElement> 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,