mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-68160 Find & Replace: preserve case bug
This commit is contained in:
@@ -633,6 +633,14 @@ public class FindManagerTest extends DaemonAnalyzerTestCase {
|
||||
|
||||
FindUtil.replace(myProject, myEditor, 0, model);
|
||||
assertEquals("FooBar fooBar", myEditor.getDocument().getText());
|
||||
|
||||
configureByText(FileTypes.PLAIN_TEXT, "abc1 Abc1 ABC1");
|
||||
|
||||
model.setStringToFind("ABC1");
|
||||
model.setStringToReplace("DEF1");
|
||||
|
||||
FindUtil.replace(myProject, myEditor, 0, model);
|
||||
assertEquals("def1 Def1 DEF1", myEditor.getDocument().getText());
|
||||
}
|
||||
|
||||
public void testFindWholeWords() {
|
||||
|
||||
@@ -864,23 +864,29 @@ public class FindManagerImpl extends FindManager {
|
||||
}
|
||||
|
||||
boolean isReplacementLowercase = true;
|
||||
boolean isReplacementUppercase = true;
|
||||
for (int i = 1; i < toReplace.length(); i++) {
|
||||
isReplacementLowercase = Character.isLowerCase(toReplace.charAt(i));
|
||||
if (!isReplacementLowercase) break;
|
||||
char replacementChar = toReplace.charAt(i);
|
||||
if (!Character.isLetter(replacementChar)) continue;
|
||||
isReplacementLowercase &= Character.isLowerCase(replacementChar);
|
||||
isReplacementUppercase &= Character.isUpperCase(replacementChar);
|
||||
if (!isReplacementLowercase && !isReplacementUppercase) break;
|
||||
}
|
||||
|
||||
boolean isTailUpper = true;
|
||||
boolean isTailLower = true;
|
||||
for (int i = 1; i < foundString.length(); i++) {
|
||||
isTailUpper &= Character.isUpperCase(foundString.charAt(i));
|
||||
isTailLower &= Character.isLowerCase(foundString.charAt(i));
|
||||
char foundChar = foundString.charAt(i);
|
||||
if (!Character.isLetter(foundChar)) continue;
|
||||
isTailUpper &= Character.isUpperCase(foundChar);
|
||||
isTailLower &= Character.isLowerCase(foundChar);
|
||||
if (!isTailUpper && !isTailLower) break;
|
||||
}
|
||||
|
||||
if (isTailUpper && isReplacementLowercase) {
|
||||
if (isTailUpper && (isReplacementLowercase || isReplacementUppercase)) {
|
||||
buffer.append(StringUtil.toUpperCase(toReplace.substring(1)));
|
||||
}
|
||||
else if (isTailLower && isReplacementLowercase) {
|
||||
else if (isTailLower && (isReplacementLowercase || isReplacementUppercase)) {
|
||||
buffer.append(toReplace.substring(1).toLowerCase());
|
||||
}
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user