FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Replace All now undoes in one shot · 2php/processing@b8910b1 · GitHub

Repository navigation

Commit b8910b1

Browse files
committed
Replace All now undoes in one shot
1 parent 5486302 commit b8910b1

3 files changed

Lines changed: 25 additions & 6 deletions

File tree

‎app/src/processing/app/syntax/JEditTextArea.java‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1429,7 +1429,6 @@ public final String getSelectedText()
14291429
}
14301430
}
14311431

1432-
14331432
/**
14341433
* Replaces the selection with the specified text.
14351434
* @param selectedText The replacement text for the selection

‎app/src/processing/app/ui/Editor.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,6 +1572,11 @@ public void setSelectedText(String what) {
15721572
}
15731573

15741574

1575+
public void setSelectedText(String what, boolean ever) {
1576+
textarea.setSelectedText(what, ever);
1577+
}
1578+
1579+
15751580
public void setSelection(int start, int stop) {
15761581
// make sure that a tool isn't asking for a bad location
15771582
start = PApplet.constrain(start, 0, textarea.getDocumentLength());

‎app/src/processing/app/ui/FindReplace.java‎

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -417,15 +417,27 @@ protected void setFound(boolean found) {
417417
replaceAndFindButton.setEnabled(found);
418418
}
419419

420+
/**
421+
* Replace the current selection with whatever's in the
422+
* replacement text field.
423+
* @param isCompoundEdit True if the action is to be marked as a copmound edit
424+
*/
425+
public void replace(boolean isCompoundEdit) {
426+
editor.setSelectedText(replaceField.getText(), isCompoundEdit);
427+
428+
editor.getSketch().setModified(true); // This necessary- calling replace()
429+
// doesn't seem to mark a sketch as modified
430+
431+
setFound(false);
432+
}
433+
420434

421435
/**
422436
* Replace the current selection with whatever's in the
423-
* replacement text field.
437+
* replacement text field, marking the action as a compound edit.
424438
*/
425439
public void replace() {
426-
editor.setSelectedText(replaceField.getText());
427-
editor.getSketch().setModified(true); // TODO is this necessary?
428-
setFound(false);
440+
replace(true);
429441
}
430442

431443

@@ -451,6 +463,8 @@ public void replaceAll() {
451463
int startTab = -1;
452464
int startIndex = -1;
453465
int counter = 10000; // prevent infinite loop
466+
467+
editor.startCompoundEdit();
454468
while (--counter > 0) {
455469
if (find(false, false)) {
456470
int caret = editor.getSelectionStart();
@@ -467,11 +481,12 @@ public void replaceAll() {
467481
startTab = editor.getSketch().getCurrentCodeIndex();
468482
startIndex = editor.getSelectionStart();
469483
}
470-
replace();
484+
replace(false);
471485
} else {
472486
break;
473487
}
474488
}
489+
editor.stopCompoundEdit();
475490
if (!foundAtLeastOne) {
476491
Toolkit.beep();
477492
}

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL