Merge pull request #2188 from Manindra29/findReplaceILfix

Fixes #2082, Find Replace infinite loop
This commit is contained in:
Ben Fry
2014-01-21 17:05:47 -08:00
+15 -2
View File
@@ -454,9 +454,22 @@ public class FindReplace extends JFrame {
editor.setSelection(0, 0);
boolean foundAtLeastOne = false;
while (true) {
int startTab = -1, startIndex = -1, c = 50000;
// you couldn't seriously be replacing 50K times o_O
while (--c > 0) {
if (find(false, false)) {
foundAtLeastOne = true;
if(editor.getSketch().getCurrentCodeIndex() == startTab
&& editor.getSelectionStart() == startIndex){
// we've reached where we started, so stop the replace
Toolkit.beep();
editor.statusNotice("Reached beginning of search!");
break;
}
if(!foundAtLeastOne){
foundAtLeastOne = true;
startTab = editor.getSketch().getCurrentCodeIndex();
startIndex = editor.getSelectionStart();
}
replace();
} else {
break;