(boolean wrap, boolean backwards)
| 250 | // look for the next instance of the find string to be found |
| 251 | // once found, select it (and go to that line) |
| 252 | private boolean find(boolean wrap, boolean backwards) { |
| 253 | String searchTerm = findField.getText(); |
| 254 | |
| 255 | // this will catch "find next" being called when no search yet |
| 256 | if (searchTerm.length() != 0) { |
| 257 | String text = editor.getText(); |
| 258 | |
| 259 | // Started work on find/replace across tabs. These two variables |
| 260 | // store the original tab and selection position so that it knew |
| 261 | // when to stop rotating through. |
| 262 | Sketch sketch = editor.getSketch(); |
| 263 | int tabIndex = sketch.getCurrentCodeIndex(); |
| 264 | |
| 265 | if (ignoreCase) { |
| 266 | searchTerm = searchTerm.toLowerCase(); |
| 267 | text = text.toLowerCase(); |
| 268 | } |
| 269 | |
| 270 | int nextIndex; |
| 271 | if (!backwards) { |
| 272 | //int selectionStart = editor.textarea.getSelectionStart(); |
| 273 | int selectionEnd = editor.getSelectionStop(); |
| 274 | |
| 275 | nextIndex = text.indexOf(searchTerm, selectionEnd); |
| 276 | if (nextIndex == -1 && wrap && !allTabs) { |
| 277 | // if wrapping, a second chance is ok, start from beginning |
| 278 | nextIndex = text.indexOf(searchTerm); |
| 279 | |
| 280 | } else if (nextIndex == -1 && allTabs) { |
| 281 | // For searching in all tabs, wrapping always happens. |
| 282 | |
| 283 | int tempIndex = tabIndex; |
| 284 | // Look for search term in all tabs. |
| 285 | while (tabIndex <= sketch.getCodeCount() - 1) { |
| 286 | if (tabIndex == sketch.getCodeCount() - 1) { |
| 287 | // System.out.println("wrapping."); |
| 288 | tabIndex = -1; |
| 289 | // removing for 4.1.2, this was never being run, but is it hiding a bug? [fry 230116] |
| 290 | // } else if (tabIndex == sketch.getCodeCount() - 1) { |
| 291 | // break; |
| 292 | } |
| 293 | |
| 294 | try { |
| 295 | Document doc = sketch.getCode(tabIndex + 1).getDocument(); |
| 296 | if(doc != null) { |
| 297 | text = doc.getText(0, doc.getLength()); // this thing has the latest changes |
| 298 | } |
| 299 | else { |
| 300 | text = sketch.getCode(tabIndex + 1).getProgram(); // not this thing. |
| 301 | } |
| 302 | } catch (BadLocationException e) { |
| 303 | e.printStackTrace(); |
| 304 | } |
| 305 | tabIndex++; |
| 306 | if (ignoreCase) { |
| 307 | text = text.toLowerCase(); |
| 308 | } |
| 309 | nextIndex = text.indexOf(searchTerm); |
no test coverage detected