Skip to content

Commit 47fcff7

Browse files
committed
Simplify FindReplace.find() logic (part 1)
The snippet: boolean wrapNeeded = false; if (wrap && nextIndex == -1) { // if wrapping, a second chance is ok, start from the end wrapNeeded = true; } is present on both sides of the `if` statement so it can be factored out.
1 parent 9723726 commit 47fcff7

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

app/src/cc/arduino/view/findreplace/FindReplace.java

+6-9
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,6 @@ private void replaceAllButtonActionPerformed(java.awt.event.ActionEvent evt) {//
284284
// End of variables declaration//GEN-END:variables
285285

286286
private boolean find(boolean wrap, boolean backwards, boolean searchTabs, int originTab) {
287-
boolean wrapNeeded = false;
288287
String search = findField.getText();
289288

290289
if (search.length() == 0) {
@@ -304,10 +303,6 @@ private boolean find(boolean wrap, boolean backwards, boolean searchTabs, int or
304303
int selectionEnd = editor.getCurrentTab().getSelectionStop();
305304

306305
nextIndex = text.indexOf(search, selectionEnd);
307-
if (wrap && nextIndex == -1) {
308-
// if wrapping, a second chance is ok, start from beginning
309-
wrapNeeded = true;
310-
}
311306
} else {
312307
// int selectionStart = editor.textarea.getSelectionStart();
313308
int selectionStart = editor.getCurrentTab().getSelectionStart() - 1;
@@ -317,10 +312,12 @@ private boolean find(boolean wrap, boolean backwards, boolean searchTabs, int or
317312
} else {
318313
nextIndex = -1;
319314
}
320-
if (wrap && nextIndex == -1) {
321-
// if wrapping, a second chance is ok, start from the end
322-
wrapNeeded = true;
323-
}
315+
}
316+
317+
boolean wrapNeeded = false;
318+
if (wrap && nextIndex == -1) {
319+
// if wrapping, a second chance is ok, start from the end
320+
wrapNeeded = true;
324321
}
325322

326323
if (nextIndex == -1) {

0 commit comments

Comments
 (0)