Replace everything that matches by doing find and replace alternately until nothing more found.
()
| 436 | * alternately until nothing more found. |
| 437 | */ |
| 438 | public void replaceAll() { |
| 439 | // move to the beginning |
| 440 | editor.setSelection(0, 0); |
| 441 | |
| 442 | boolean foundAtLeastOne = false; |
| 443 | int startTab = -1; |
| 444 | int startIndex = -1; |
| 445 | int counter = 10000; // prevent infinite loop |
| 446 | |
| 447 | editor.startCompoundEdit(); |
| 448 | while (--counter > 0) { |
| 449 | if (find(false, false)) { |
| 450 | int caret = editor.getSelectionStart(); |
| 451 | int stopIndex = startIndex + replaceField.getText().length(); |
| 452 | if (editor.getSketch().getCurrentCodeIndex() == startTab && |
| 453 | (caret >= startIndex && (caret <= stopIndex))) { |
| 454 | // we've reached where we started, so stop the replacement |
| 455 | Toolkit.beep(); |
| 456 | editor.statusNotice("Reached beginning of search!"); |
| 457 | break; |
| 458 | } |
| 459 | if (!foundAtLeastOne) { |
| 460 | foundAtLeastOne = true; |
| 461 | startTab = editor.getSketch().getCurrentCodeIndex(); |
| 462 | startIndex = editor.getSelectionStart(); |
| 463 | } |
| 464 | replace(false); |
| 465 | } else { |
| 466 | break; |
| 467 | } |
| 468 | } |
| 469 | editor.stopCompoundEdit(); |
| 470 | if (!foundAtLeastOne) { |
| 471 | Toolkit.beep(); |
| 472 | } |
| 473 | setFound(false); |
| 474 | } |
| 475 | |
| 476 | |
| 477 | public void setFindText(String t) { |
no test coverage detected