From ae8b2200e06474e4bdfcdf47a438abd8e8c7bf71 Mon Sep 17 00:00:00 2001 From: Ekaterina Tuzova Date: Fri, 26 Jul 2013 15:32:45 +0400 Subject: [PATCH] fixed PY-9637 Extract Method: Replace Duplicates: remove highlighting after skip --- .../extractMethod/ExtractMethodHelper.java | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/refactoring/extractMethod/ExtractMethodHelper.java b/platform/lang-impl/src/com/intellij/refactoring/extractMethod/ExtractMethodHelper.java index 1d7bcaa321c4..9b1dd1601867 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/extractMethod/ExtractMethodHelper.java +++ b/platform/lang-impl/src/com/intellij/refactoring/extractMethod/ExtractMethodHelper.java @@ -25,6 +25,7 @@ import com.intellij.openapi.editor.LogicalPosition; import com.intellij.openapi.editor.ScrollType; import com.intellij.openapi.editor.colors.EditorColors; import com.intellij.openapi.editor.colors.EditorColorsManager; +import com.intellij.openapi.editor.markup.RangeHighlighter; import com.intellij.openapi.editor.markup.TextAttributes; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.ProgressManager; @@ -40,7 +41,10 @@ import com.intellij.ui.ReplacePromptDialog; import com.intellij.util.Consumer; import org.jetbrains.annotations.NotNull; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * @author Dennis.Ushakov @@ -93,19 +97,26 @@ public class ExtractMethodHelper { DialogWrapper.OK_EXIT_CODE; if (exitCode == DialogWrapper.OK_EXIT_CODE) { boolean replaceAll = false; + final Map highlighterMap = new HashMap(); for (SimpleMatch match : duplicates) { final Pair replacement = Pair.create(match, callElement); if (!replaceAll) { - highlightInEditor(project, match, editor); + highlightInEditor(project, match, editor, highlighterMap); int promptResult = FindManager.PromptResult.ALL; + //noinspection ConstantConditions if (!isUnittest) { ReplacePromptDialog promptDialog = new ReplacePromptDialog(false, RefactoringBundle.message("replace.fragment"), project); promptDialog.show(); promptResult = promptDialog.getExitCode(); } - if (promptResult == FindManager.PromptResult.SKIP) continue; + if (promptResult == FindManager.PromptResult.SKIP) { + final HighlightManager highlightManager = HighlightManager.getInstance(project); + final RangeHighlighter highlighter = highlighterMap.get(match); + if (highlighter != null) highlightManager.removeSegmentHighlighter(editor, highlighter); + continue; + } if (promptResult == FindManager.PromptResult.CANCEL) break; if (promptResult == FindManager.PromptResult.OK) { @@ -139,14 +150,17 @@ public class ExtractMethodHelper { }, "Replace duplicate", null); } + private static void highlightInEditor(@NotNull final Project project, @NotNull final SimpleMatch match, - @NotNull final Editor editor) { + @NotNull final Editor editor, Map highlighterMap) { + final List highlighters = new ArrayList(); final HighlightManager highlightManager = HighlightManager.getInstance(project); final EditorColorsManager colorsManager = EditorColorsManager.getInstance(); final TextAttributes attributes = colorsManager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES); final int startOffset = match.getStartElement().getTextRange().getStartOffset(); final int endOffset = match.getEndElement().getTextRange().getEndOffset(); - highlightManager.addRangeHighlight(editor, startOffset, endOffset, attributes, true, null); + highlightManager.addRangeHighlight(editor, startOffset, endOffset, attributes, true, highlighters); + highlighterMap.put(match, highlighters.get(0)); final LogicalPosition logicalPosition = editor.offsetToLogicalPosition(startOffset); editor.getScrollingModel().scrollTo(logicalPosition, ScrollType.MAKE_VISIBLE); }