Skip to content

Commit 86ebec4

Browse files
committed
This revision cleans up the changes to FindReplace classes made in the
previous commit. We really need a better collection of unit tests for find/replace operations. The following files were modified, added, or removed: modified: src/edu/rice/cs/drjava/model/FindReplaceMachine.java modified: src/edu/rice/cs/drjava/ui/FindReplacePanel.java
1 parent 7c0ce63 commit 86ebec4

File tree

2 files changed

+19
-22
lines changed

2 files changed

+19
-22
lines changed

drjava/src/edu/rice/cs/drjava/model/FindReplaceMachine.java

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -407,11 +407,11 @@ else if (_searchSelectionOnly) {
407407
* _selectionRegion and _isForward. Ignores value of _searchAllDocuments. Processes selected region (which may be
408408
* the whole document) sequentially depending on find direction. This convention ensures that matches created by
409409
* string replacement will not be replaced as in the following example:<p>
410-
* findString: "hello"<br>
411-
* replaceString: "e"<br>
410+
* findString: "e"<br>
411+
* replaceString: "hello"<br>
412412
* document text: "hhellollo"<p>
413413
* Only executes in event thread. Assumes (i) this has exclusive access to _doc (since it only runs in event thread)
414-
* and (ii) findAction does not modify _doc.
414+
* and (ii) findAction does not modify _doc (What about replacement?)
415415
* @param findAction action to perform on the occurrences; input is the FindResult, output is ignored
416416
* @return the number of replacements
417417
*/
@@ -488,24 +488,21 @@ private FindResult findNext(boolean searchAll) {
488488
}
489489

490490

491-
/** Finds next match in specified doc only. If searching forward, len must
492-
* be doc.getLength(). If searching backward, start must be 0. If
493-
* searchAll, suppress executing in-document wrapped search, because it
494-
* must be deferred. Only runs in the event thread. Note than this method
495-
* does a wrapped search if specified search fails.
496-
* @param doc the document to search in
497-
* @param start the start offset for searching
498-
* @param len the length to search
499-
* @param searchAll flao
500-
* @return the next match in the specified document
501-
*/
491+
/** Finds next match in specified doc only. If searching forward, len must be doc.getLength(). If searching
492+
* backward, start must be 0. If searchAll, suppress executing in-document wrapped search, because it must be
493+
* deferred. Only runs in the event thread. Note than this method does a wrapped search if specified search fails.
494+
* @param doc the document to search in
495+
* @param start the start offset for searching
496+
* @param len the length to search
497+
* @param searchAll flao
498+
* @return the next match in the specified document
499+
*/
502500
private FindResult _findNextInDoc(OpenDefinitionsDocument doc, int start, int len, boolean searchAll) {
503501

504502
assert EventQueue.isDispatchThread() || Utilities.TEST_MODE;
505503

506504
// search from current position to "end" of document ("end" is start if searching backward)
507-
// Utilities.show("_findNextInDoc([" + doc.getText() + "], " + start + ", " + len + ", " + searchAll + ")");
508-
// _log.log("_findNextInDoc([" + doc.getText() + "], " + start + ", " + len + ", " + searchAll + ")");
505+
_log.log("_findNextInDoc([" + doc.getText() + "], " + start + ", " + len + ", " + searchAll + ")");
509506
FindResult fr = _findNextInDocSegment(doc, start, len);
510507
if (fr.getFoundOffset() >= 0 || searchAll) return fr;
511508

drjava/src/edu/rice/cs/drjava/ui/FindReplacePanel.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ private void _findAll() {
586586
_log.log("Refreshing active document after 'find all'");
587587
_model.refreshActiveDocument(); // Rationale: a giant findAll left the definitions pane is a strange state
588588
panel.requestFocusInWindow();
589-
EventQueue.invokeLater(new Runnable() { public void run() { panel.getRegTree().scrollRowToVisible(0); } });
589+
// EventQueue.invokeLater(new Runnable() { public void run() { panel.getRegTree().scrollRowToVisible(0); } });
590590
}
591591

592592
/** Performs "find all" with the specified options.
@@ -753,12 +753,12 @@ private void _replaceAll() {
753753

754754
_frame.hourglassOn();
755755
int count = 0;
756-
Runnable1<FindResult> doNothing = new Runnable1<FindResult>() {
757-
public void run(FindResult fr) { }
758-
};
756+
Runnable1<FindResult> replaceMatchingString = // replaces current (found) string
757+
new Runnable1<FindResult>() {
758+
public void run(FindResult fr) { _machine.replaceCurrent(); }};
759759
try {
760760
/* Replace all matching strings in region (which may be entire project). */
761-
count = _machine.processAll(doNothing, region);
761+
count = _machine.processAll(replaceMatchingString, region);
762762
}
763763
finally {
764764
_frame.hourglassOff();
@@ -786,7 +786,7 @@ public void run(FindResult fr) { }
786786

787787
_log.log("Refreshing active document after 'replace all'");
788788
_model.refreshActiveDocument(); // Rationale: a giant findAll left the definitions pane is a strange state
789-
// panel.requestFocusInWindow();
789+
_findField.requestFocusInWindow();
790790
// EventQueue.invokeLater(new Runnable() { public void run() { panel.getRegTree().scrollRowToVisible(0); } });
791791
}
792792

0 commit comments

Comments
 (0)