Skip to content

Commit c4c5558

Browse files
committed
Slightly simplify subroutine
1 parent 66a001c commit c4c5558

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

app/src/cc/arduino/packages/formatter/clangformat/ClangFormat.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545

4646
import processing.app.Base;
4747
import processing.app.Editor;
48+
import processing.app.EditorTab;
4849
import processing.app.helpers.ProcessUtils;
4950

5051
public class ClangFormat implements Runnable {
@@ -59,16 +60,17 @@ public ClangFormat(Editor editor) {
5960

6061
@Override
6162
public void run() {
62-
String originalText = editor.getCurrentTab().getText();
63-
int cursorOffset = editor.getCurrentTab().getTextArea().getCaretPosition();
63+
EditorTab tab = editor.getCurrentTab();
64+
String originalText = tab.getText();
65+
int cursorOffset = tab.getTextArea().getCaretPosition();
6466
try {
6567
FormatResult result = runClangFormatOn(originalText, cursorOffset);
6668
if (result.FormattedText.equals(originalText)) {
6769
editor.statusNotice(tr("No changes necessary for Auto Format."));
6870
return;
6971
}
70-
editor.getCurrentTab().setText(result.FormattedText);
71-
editor.getCurrentTab().getTextArea().setCaretPosition(result.Cursor);
72+
tab.setText(result.FormattedText);
73+
tab.getTextArea().setCaretPosition(result.Cursor);
7274
editor.statusNotice(tr("Auto Format finished."));
7375
} catch (IOException | InterruptedException e) {
7476
editor.statusError("Auto format error: " + e.getMessage());

0 commit comments

Comments
 (0)