diff --git a/app/src/processing/app/FindReplace.java b/app/src/processing/app/FindReplace.java index 922bcc9ba..57c851dd7 100644 --- a/app/src/processing/app/FindReplace.java +++ b/app/src/processing/app/FindReplace.java @@ -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;