Skip to content

Commit fb9b3bf

Browse files
author
Ben Fry
committed
clean up formatting/readability
1 parent 98a0d4d commit fb9b3bf

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

app/src/processing/app/ui/FindReplace.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -448,20 +448,21 @@ public void replaceAll() {
448448
editor.setSelection(0, 0);
449449

450450
boolean foundAtLeastOne = false;
451-
int startTab = -1, startIndex = -1, c = 50000;
452-
// you couldn't seriously be replacing 50K times o_O
453-
while (--c > 0) {
451+
int startTab = -1;
452+
int startIndex = -1;
453+
int counter = 10000; // prevent infinite loop
454+
while (--counter > 0) {
454455
if (find(false, false)) {
455-
if (editor.getSketch().getCurrentCodeIndex() == startTab
456-
&& (editor.getSelectionStart() >= startIndex && (editor
457-
.getSelectionStart() <= startIndex
458-
+ replaceField.getText().length()))) {
456+
int caret = editor.getSelectionStart();
457+
int stopIndex = startIndex + replaceField.getText().length();
458+
if (editor.getSketch().getCurrentCodeIndex() == startTab &&
459+
(caret >= startIndex && (caret <= stopIndex))) {
459460
// we've reached where we started, so stop the replace
460461
Toolkit.beep();
461462
editor.statusNotice("Reached beginning of search!");
462463
break;
463464
}
464-
if(!foundAtLeastOne){
465+
if (!foundAtLeastOne) {
465466
foundAtLeastOne = true;
466467
startTab = editor.getSketch().getCurrentCodeIndex();
467468
startIndex = editor.getSelectionStart();

0 commit comments

Comments
 (0)