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);
                    }
                }
        );
0
3 comments

In IDEA 2024, the code formatting is done by class ReformatCodeProcessor in a background thread.

Ref: com.intellij.codeInsight.actions.ReformatCodeAction

Use this code:

new ReformatCodeProcessor(PsiDocumentManager.getInstance(myProject).getPsiFile(document),false).run();
0

Great job,  after replace the code, it works fine.
Thank you Jacky Liu.

0

¿Este fragmento de código sirve para modificar y formatear un documento en la plataforma IntelliJ IDEA?

0

Please sign in to leave a comment.