| 272 | // look for the next instance of the find string to be found |
| 273 | // once found, select it (and go to that line) |
| 274 | private boolean find(boolean wrap, boolean backwards) { |
| 275 | String searchTerm = findField.getText(); |
| 276 | |
| 277 | // this will catch "find next" being called when no search yet |
| 278 | if (searchTerm.length() != 0) { |
| 279 | String text = editor.getText(); |
| 280 | |
| 281 | // Started work on find/replace across tabs. These two variables store |
| 282 | // the original tab and selection position so that it knew when to stop |
| 283 | // rotating through. |
| 284 | Sketch sketch = editor.getSketch(); |
| 285 | int tabIndex = sketch.getCurrentCodeIndex(); |
| 286 | // int selIndex = backwards ? |
| 287 | // editor.getSelectionStart() : editor.getSelectionStop(); |
| 288 | |
| 289 | if (ignoreCase) { |
| 290 | searchTerm = searchTerm.toLowerCase(); |
| 291 | text = text.toLowerCase(); |
| 292 | } |
| 293 | |
| 294 | int nextIndex; |
| 295 | if (!backwards) { |
| 296 | //int selectionStart = editor.textarea.getSelectionStart(); |
| 297 | int selectionEnd = editor.getSelectionStop(); |
| 298 | |
| 299 | nextIndex = text.indexOf(searchTerm, selectionEnd); |
| 300 | if (nextIndex == -1 && wrap && !allTabs) { |
| 301 | // if wrapping, a second chance is ok, start from beginning |
| 302 | nextIndex = text.indexOf(searchTerm, 0); |
| 303 | |
| 304 | } else if (nextIndex == -1 && allTabs) { |
| 305 | // For searching in all tabs, wrapping always happens. |
| 306 | |
| 307 | int tempIndex = tabIndex; |
| 308 | // Look for searchterm in all tabs. |
| 309 | while (tabIndex <= sketch.getCodeCount() - 1) { |
| 310 | if (tabIndex == sketch.getCodeCount() - 1) { |
| 311 | // System.out.println("wrapping."); |
| 312 | tabIndex = -1; |
| 313 | } else if (tabIndex == sketch.getCodeCount() - 1) { |
| 314 | break; |
| 315 | } |
| 316 | |
| 317 | try { |
| 318 | Document doc = sketch.getCode(tabIndex + 1).getDocument(); |
| 319 | if(doc != null) { |
| 320 | text = doc.getText(0, doc.getLength()); // this thing has the latest changes |
| 321 | } |
| 322 | else { |
| 323 | text = sketch.getCode(tabIndex + 1).getProgram(); // not this thing. |
| 324 | } |
| 325 | } catch (BadLocationException e) { |
| 326 | e.printStackTrace(); |
| 327 | } |
| 328 | tabIndex++; |
| 329 | if (ignoreCase) { |
| 330 | text = text.toLowerCase(); |
| 331 | } |