mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
use rearrange code processor instead of direct call, fix for possible ReadOnlyModificationException
This commit is contained in:
@@ -187,23 +187,11 @@ public class ReformatCodeAction extends AnAction implements DumbAware {
|
||||
}
|
||||
|
||||
if (rearrangeEntries && file != null && editor != null) {
|
||||
final ArrangementEngine engine = ServiceManager.getService(project, ArrangementEngine.class);
|
||||
try {
|
||||
final PsiFile finalFile = file;
|
||||
SelectionModel selectionModel = editor.getSelectionModel();
|
||||
final TextRange rangeToUse = selectionModel.hasSelection()
|
||||
? TextRange.create(selectionModel.getSelectionStart(), selectionModel.getSelectionEnd())
|
||||
: TextRange.create(0, editor.getDocument().getTextLength());
|
||||
CommandProcessor.getInstance().executeCommand(project, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
engine.arrange(editor, finalFile, Collections.singleton(rangeToUse));
|
||||
}
|
||||
}, getTemplatePresentation().getText(), null);
|
||||
}
|
||||
finally {
|
||||
PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument());
|
||||
}
|
||||
SelectionModel selectionModel = editor.getSelectionModel();
|
||||
final TextRange rangeToUse = selectionModel.hasSelection()
|
||||
? TextRange.create(selectionModel.getSelectionStart(), selectionModel.getSelectionEnd())
|
||||
: TextRange.create(0, editor.getDocument().getTextLength());
|
||||
new RearrangeCodeProcessor(project, file, Collections.singleton(rangeToUse)).run();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user