From 3a499bbf91d2cbab23efab19c76e559f6cc64642 Mon Sep 17 00:00:00 2001 From: "Maxim.Mossienko" Date: Tue, 16 Jun 2015 19:49:44 +0200 Subject: [PATCH] - replace in path replaces already processed text in certain cases ( IDEA-141232) - Show full path in the Dialog in Find/Replace Path (IDEA-138684) --- .../ReplaceInProjectManager.java | 17 ++++++++++++----- .../src/messages/FindBundle.properties | 2 +- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/find/replaceInProject/ReplaceInProjectManager.java b/platform/lang-impl/src/com/intellij/find/replaceInProject/ReplaceInProjectManager.java index dbee212b2cd8..a68623380967 100644 --- a/platform/lang-impl/src/com/intellij/find/replaceInProject/ReplaceInProjectManager.java +++ b/platform/lang-impl/src/com/intellij/find/replaceInProject/ReplaceInProjectManager.java @@ -254,11 +254,11 @@ public class ReplaceInProjectManager { final PsiFile psiFile = elt.getContainingFile(); if (!psiFile.isWritable()) continue; + final VirtualFile virtualFile = psiFile.getVirtualFile(); + Runnable selectOnEditorRunnable = new Runnable() { @Override public void run() { - final VirtualFile virtualFile = psiFile.getVirtualFile(); - if (virtualFile != null && ApplicationManager.getApplication().runReadAction(new Computable() { @Override public Boolean compute() { @@ -274,9 +274,15 @@ public class ReplaceInProjectManager { } }; + String path = ApplicationManager.getApplication().runReadAction(new Computable() { + @Override + public String compute() { + return virtualFile != null ? virtualFile.getPath() : null; + } + }); CommandProcessor.getInstance() .executeCommand(myProject, selectOnEditorRunnable, FindBundle.message("find.replace.select.on.editor.command"), null); - String title = FindBundle.message("find.replace.found.usage.title", i + 1, usages.length); + String title = FindBundle.message("find.replace.found.usage.title", i + 1, usages.length, path); int result; try { @@ -479,7 +485,6 @@ public class ReplaceInProjectManager { return result; } - private boolean getStringToReplace(int textOffset, int textEndOffset, Document document, FindModel findModel, Ref stringToReplace) @@ -494,7 +499,9 @@ public class ReplaceInProjectManager { final CharSequence foundString = document.getCharsSequence().subSequence(textOffset, textEndOffset); PsiFile file = PsiDocumentManager.getInstance(myProject).getPsiFile(document); FindResult findResult = findManager.findString(document.getCharsSequence(), textOffset, findModel, file != null ? file.getVirtualFile() : null); - if (!findResult.isStringFound()) { + if (!findResult.isStringFound() || + // find result should be in needed range + !(findResult.getStartOffset() >= textOffset && findResult.getEndOffset() <= textEndOffset) ) { return false; } diff --git a/platform/platform-resources-en/src/messages/FindBundle.properties b/platform/platform-resources-en/src/messages/FindBundle.properties index 0d1765cd5d02..48bd5de8d47c 100644 --- a/platform/platform-resources-en/src/messages/FindBundle.properties +++ b/platform/platform-resources-en/src/messages/FindBundle.properties @@ -124,7 +124,7 @@ find.usage.view.usages.text=occurrences of ''{0}'' find.replace.occurrences.found.in.read.only.files.status=Occurrences found in read-only files find.replace.select.on.editor.command=Select on Editor -find.replace.found.usage.title=Replace Usage {0} of {1} Found +find.replace.found.usage.title=Replace Usage {0} of {1} Found - {2} find.replace.command=Replace find.replace.all.action=Replace All find.replace.all.action.description=&Do Replace Al&&l