mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-167546 Find/Replace nonfunctional when newlines are embedded in the Find textbox
This commit is contained in:
@@ -921,6 +921,23 @@ public class FindManagerTest extends DaemonAnalyzerTestCase {
|
||||
assertTrue(!findResult.isStringFound());
|
||||
}
|
||||
|
||||
public void testRegExpMatchReplacement() throws InterruptedException, FindManager.MalformedReplacementStringException {
|
||||
String text = "final override val\n" +
|
||||
" d1PrimitiveType by lazyThreadSafeIdempotentGenerator { D1PrimitiveType( typeManager = this ) }";
|
||||
String pattern = "final override val\n" +
|
||||
"d(\\w+)PrimitiveType by lazyThreadSafeIdempotentGenerator \\{ D(\\w+)PrimitiveType\\( typeManager = this \\) \\}";
|
||||
String replacement = "";
|
||||
|
||||
FindModel findModel = FindManagerTestUtils.configureFindModel(pattern);
|
||||
|
||||
findModel.setRegularExpressions(true);
|
||||
findModel.setMultiline(true);
|
||||
|
||||
FindResult findResult = myFindManager.findString(text, 0, findModel, null);
|
||||
assertTrue(findResult.isStringFound());
|
||||
assertEquals(replacement, myFindManager.getStringToReplace(findResult.substring(text), findModel, 0, text));
|
||||
}
|
||||
|
||||
public void testRegExpSearchDoesCheckCancelled() throws InterruptedException {
|
||||
String text = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
|
||||
FindModel findModel = FindManagerTestUtils.configureFindModel("(x+x+)+y");
|
||||
|
||||
@@ -77,7 +77,6 @@ import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.regex.PatternSyntaxException;
|
||||
|
||||
public class FindManagerImpl extends FindManager {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.find.impl.FindManagerImpl");
|
||||
@@ -840,6 +839,7 @@ public class FindManagerImpl extends FindManager {
|
||||
}
|
||||
|
||||
private static Matcher compileRegexAndFindFirst(FindModel model, CharSequence text, int startOffset) {
|
||||
model = normalizeIfMultilined(model);
|
||||
Matcher matcher = compileRegExp(model, text);
|
||||
|
||||
if (model.isForward()){
|
||||
@@ -866,38 +866,6 @@ public class FindManagerImpl extends FindManager {
|
||||
return new MalformedReplacementStringException(FindBundle.message("find.replace.invalid.replacement.string", model.getStringToReplace()), e);
|
||||
}
|
||||
|
||||
private static String getStringToReplaceByRegexp0(String foundString, final FindModel model) throws MalformedReplacementStringException{
|
||||
String toFind = model.getStringToFind();
|
||||
String toReplace = model.getStringToReplace();
|
||||
Pattern pattern;
|
||||
try{
|
||||
int flags = Pattern.MULTILINE;
|
||||
if (!model.isCaseSensitive()) {
|
||||
flags |= Pattern.CASE_INSENSITIVE;
|
||||
}
|
||||
pattern = Pattern.compile(toFind, flags);
|
||||
}
|
||||
catch(PatternSyntaxException e){
|
||||
return toReplace;
|
||||
}
|
||||
|
||||
Matcher matcher = pattern.matcher(foundString);
|
||||
if (matcher.matches()) {
|
||||
try {
|
||||
return matcher.replaceAll(StringUtil.unescapeStringCharacters(toReplace));
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw createMalformedReplacementException(model, e);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// There are valid situations (for example, IDEADEV-2543 or positive lookbehind assertions)
|
||||
// where an expression which matches a string in context will not match the same string
|
||||
// separately).
|
||||
return toReplace;
|
||||
}
|
||||
}
|
||||
|
||||
private static String replaceWithCaseRespect(String toReplace, String foundString) {
|
||||
if (foundString.isEmpty() || toReplace.isEmpty()) return toReplace;
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
|
||||
Reference in New Issue
Block a user