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:
parent
15089f0c54
commit
2ba0124871
@ -76,7 +76,16 @@ public class AStyle implements Tool {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
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);
|
String formattedText = aStyleInterface.AStyleMain(originalText, formatterConfiguration);
|
||||||
|
|
||||||
if (formattedText.equals(originalText)) {
|
if (formattedText.equals(originalText)) {
|
||||||
@ -84,7 +93,10 @@ public class AStyle implements Tool {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
editor.getCurrentTab().setText(formattedText);
|
if(selection)
|
||||||
|
editor.getCurrentTab().setSelectedText(formattedText);
|
||||||
|
else
|
||||||
|
editor.getCurrentTab().setText(formattedText);
|
||||||
|
|
||||||
// mark as finished
|
// mark as finished
|
||||||
editor.statusNotice(tr("Auto Format finished."));
|
editor.statusNotice(tr("Auto Format finished."));
|
||||||
@ -95,4 +107,4 @@ public class AStyle implements Tool {
|
|||||||
return tr("Auto Format");
|
return tr("Auto Format");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user