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.
This commit is contained in:
Cristian Maglie 2016-09-20 13:52:24 +02:00
parent 9723726387
commit 47fcff77d5
1 changed files with 6 additions and 9 deletions

View File

@ -284,7 +284,6 @@ public class FindReplace extends javax.swing.JFrame {
// End of variables declaration//GEN-END:variables
private boolean find(boolean wrap, boolean backwards, boolean searchTabs, int originTab) {
boolean wrapNeeded = false;
String search = findField.getText();
if (search.length() == 0) {
@ -304,10 +303,6 @@ public class FindReplace extends javax.swing.JFrame {
int selectionEnd = editor.getCurrentTab().getSelectionStop();
nextIndex = text.indexOf(search, selectionEnd);
if (wrap && nextIndex == -1) {
// if wrapping, a second chance is ok, start from beginning
wrapNeeded = true;
}
} else {
// int selectionStart = editor.textarea.getSelectionStart();
int selectionStart = editor.getCurrentTab().getSelectionStart() - 1;
@ -317,10 +312,12 @@ public class FindReplace extends javax.swing.JFrame {
} else {
nextIndex = -1;
}
if (wrap && nextIndex == -1) {
// if wrapping, a second chance is ok, start from the end
wrapNeeded = true;
}
}
boolean wrapNeeded = false;
if (wrap && nextIndex == -1) {
// if wrapping, a second chance is ok, start from the end
wrapNeeded = true;
}
if (nextIndex == -1) {