LanguageTextField setText hang
Answered
Please see the code, I have rewritre the setText method.
Document document = getDocument();
((DocumentImpl)document).setAcceptSlashR(true);
WriteCommandAction.runWriteCommandAction(
myProject,
() -> {
document.setText(finalText);
PsiDocumentManager.getInstance(myProject).commitDocument(document);
if(formatFlag && StringUtils.isNotBlank(finalText)){
PsiFile psiFile = PsiDocumentManager.getInstance(myProject).getPsiFile(document);
CodeStyleManager.getInstance(myProject).reformat(psiFile);
}
}
);
Please sign in to leave a comment.
In IDEA 2024, the code formatting is done by class
ReformatCodeProcessor
in a background thread.Ref:
com.intellij.codeInsight.actions.ReformatCodeAction
Use this code:
Great job, after replace the code, it works fine.
Thank you Jacky Liu.
¿Este fragmento de código sirve para modificar y formatear un documento en la plataforma IntelliJ IDEA?