Replace everything that matches by doing find and replace alternately until nothing more found.
()
| 457 | * alternately until nothing more found. |
| 458 | */ |
| 459 | public void replaceAll() { |
| 460 | // move to the beginning |
| 461 | editor.setSelection(0, 0); |
| 462 | |
| 463 | boolean foundAtLeastOne = false; |
| 464 | int startTab = -1; |
| 465 | int startIndex = -1; |
| 466 | int counter = 10000; // prevent infinite loop |
| 467 | |
| 468 | editor.startCompoundEdit(); |
| 469 | while (--counter > 0) { |
| 470 | if (find(false, false)) { |
| 471 | int caret = editor.getSelectionStart(); |
| 472 | int stopIndex = startIndex + replaceField.getText().length(); |
| 473 | if (editor.getSketch().getCurrentCodeIndex() == startTab && |
| 474 | (caret >= startIndex && (caret <= stopIndex))) { |
| 475 | // we've reached where we started, so stop the replace |
| 476 | Toolkit.beep(); |
| 477 | editor.statusNotice("Reached beginning of search!"); |
| 478 | break; |
| 479 | } |
| 480 | if (!foundAtLeastOne) { |
| 481 | foundAtLeastOne = true; |
| 482 | startTab = editor.getSketch().getCurrentCodeIndex(); |
| 483 | startIndex = editor.getSelectionStart(); |
| 484 | } |
| 485 | replace(false); |
| 486 | } else { |
| 487 | break; |
| 488 | } |
| 489 | } |
| 490 | editor.stopCompoundEdit(); |
| 491 | if (!foundAtLeastOne) { |
| 492 | Toolkit.beep(); |
| 493 | } |
| 494 | setFound(false); |
| 495 | } |
| 496 | |
| 497 | |
| 498 | public void setFindText(String t) { |
no test coverage detected