|
33 | 33 | import processing.app.BaseNoGui;
|
34 | 34 | import processing.app.Editor;
|
35 | 35 | import processing.app.helpers.FileUtils;
|
36 |
| -import processing.app.syntax.SketchTextArea; |
37 | 36 | import processing.app.tools.Tool;
|
38 | 37 |
|
39 |
| -import javax.swing.text.BadLocationException; |
40 | 38 | import java.io.File;
|
41 | 39 | import java.io.IOException;
|
42 | 40 |
|
@@ -86,53 +84,12 @@ public void run() {
|
86 | 84 | return;
|
87 | 85 | }
|
88 | 86 |
|
89 |
| - SketchTextArea textArea = editor.getCurrentTab().getTextArea(); |
90 |
| - |
91 |
| - int line = getLineOfOffset(textArea); |
92 |
| - int lineOffset = getLineOffset(textArea, line); |
93 |
| - |
94 | 87 | editor.getCurrentTab().setText(formattedText);
|
95 | 88 |
|
96 |
| - if (line != -1 && lineOffset != -1) { |
97 |
| - try { |
98 |
| - setCaretPosition(textArea, line, lineOffset); |
99 |
| - } catch (BadLocationException e) { |
100 |
| - e.printStackTrace(); |
101 |
| - } |
102 |
| - } |
103 |
| - |
104 | 89 | // mark as finished
|
105 | 90 | editor.statusNotice(tr("Auto Format finished."));
|
106 | 91 | }
|
107 | 92 |
|
108 |
| - private void setCaretPosition(SketchTextArea textArea, int line, int lineOffset) throws BadLocationException { |
109 |
| - int caretPosition; |
110 |
| - if (line < textArea.getLineCount()) { |
111 |
| - caretPosition = Math.min(textArea.getLineStartOffset(line) + lineOffset, textArea.getLineEndOffset(line) - 1); |
112 |
| - } else { |
113 |
| - caretPosition = textArea.getText().length() - 1; |
114 |
| - } |
115 |
| - textArea.setCaretPosition(caretPosition); |
116 |
| - } |
117 |
| - |
118 |
| - private int getLineOffset(SketchTextArea textArea, int line) { |
119 |
| - try { |
120 |
| - return textArea.getCaretPosition() - textArea.getLineStartOffset(line); |
121 |
| - } catch (BadLocationException e) { |
122 |
| - e.printStackTrace(); |
123 |
| - } |
124 |
| - return -1; |
125 |
| - } |
126 |
| - |
127 |
| - private int getLineOfOffset(SketchTextArea textArea) { |
128 |
| - try { |
129 |
| - return textArea.getLineOfOffset(textArea.getCaretPosition()); |
130 |
| - } catch (BadLocationException e) { |
131 |
| - e.printStackTrace(); |
132 |
| - } |
133 |
| - return -1; |
134 |
| - } |
135 |
| - |
136 | 93 | @Override
|
137 | 94 | public String getMenuTitle() {
|
138 | 95 | return tr("Auto Format");
|
|
0 commit comments