Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions app/src/cc/arduino/packages/formatter/AStyle.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,27 @@ public void init(Editor editor) {

@Override
public void run() {
String originalText = editor.getCurrentTab().getText();

String originalText = editor.getCurrentTab().getSelectedText();
boolean selection = true;

// If no selection use all file
if(originalText == null || originalText.isEmpty()) {
originalText = editor.getCurrentTab().getText();
selection = false;
}

String formattedText = aStyleInterface.AStyleMain(originalText, formatterConfiguration);

if (formattedText.equals(originalText)) {
editor.statusNotice(tr("No changes necessary for Auto Format."));
return;
}

editor.getCurrentTab().setText(formattedText);
if(selection)
editor.getCurrentTab().setSelectedText(formattedText);
else
editor.getCurrentTab().setText(formattedText);

// mark as finished
editor.statusNotice(tr("Auto Format finished."));
Expand All @@ -95,4 +107,4 @@ public String getMenuTitle() {
return tr("Auto Format");
}

}
}