1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-02-26 20:54:22 +01:00

[editor] Allow formatting only the selection

This commit is contained in:
Ricardo JL Rufino 2020-05-14 01:31:22 -03:00
parent 15089f0c54
commit 2ba0124871

View File

@ -76,7 +76,16 @@ public class AStyle implements Tool {
@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)) {
@ -84,7 +93,10 @@ public class AStyle implements Tool {
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."));
@ -95,4 +107,4 @@ public class AStyle implements Tool {
return tr("Auto Format");
}
}
}