File tree Expand file tree Collapse file tree
app/src/processing/app/ui Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ();
You can’t perform that action at this time.
0 commit comments