3232import processing .app .tools .Tool ;
3333
3434
35+
3536/**
3637 * Example Tools menu entry.
3738 */
@@ -69,8 +70,9 @@ public void run() {
6970
7071
7172 protected void mangleSelection () {
72- if (editor .isSelectionActive ()) {
73- String selection = editor .getSelectedText ();
73+ //Check if there is selected text
74+ if (editor .getCurrentTab ().getSelectedText () != null ) {
75+ String selection = editor .getCurrentTab ().getSelectedText ();
7476 char [] stuff = selection .toCharArray ();
7577 // Randomly swap a bunch of characters in the text
7678 for (int i = 0 ; i < stuff .length / 10 ; i ++) {
@@ -82,13 +84,12 @@ protected void mangleSelection() {
8284 stuff [a ] = selection .charAt (b );
8385 stuff [b ] = selection .charAt (a );
8486 }
85- editor .startCompoundEdit ();
86- editor .setSelectedText (new String (stuff ));
87- editor .stopCompoundEdit ();
87+ editor .getCurrentTab ().setSelectedText (new String (stuff ));
8888 editor .statusNotice ("Now that feels better, doesn't it?" );
8989
9090 } else {
91- editor .statusError ("No selection, no dice." );
91+ //When there is no selected text
92+ editor .statusError ("No selection, no dice." );
9293 }
9394 }
9495}
0 commit comments