Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[editor] Allow formatting only the selection #10204

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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()) {
ricardojlrufino marked this conversation as resolved.
Show resolved Hide resolved
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");
}

}
}
ricardojlrufino marked this conversation as resolved.
Show resolved Hide resolved