mirror of https://gitee.com/makejava/EasyCode.git
修复首次生成新文件,会存在文档对象不存在BUG
This commit is contained in:
parent
3e8b0a56cc
commit
012f2cc1d8
|
@ -249,7 +249,9 @@ public class SaveFile {
|
|||
FileUtils.getInstance().reformatFile(project, file);
|
||||
}
|
||||
// 提交文档改动,并非VCS中的提交文件
|
||||
psiDocumentManager.commitDocument(document);
|
||||
if (document != null) {
|
||||
psiDocumentManager.commitDocument(document);
|
||||
}
|
||||
}
|
||||
|
||||
private String getFileText(VirtualFile file) {
|
||||
|
|
|
@ -109,7 +109,14 @@ public class FileUtils {
|
|||
FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
|
||||
Document document = fileDocumentManager.getDocument(file);
|
||||
if (document == null) {
|
||||
throw new IllegalStateException("获取文档对象失败,fileName:" + fileName);
|
||||
WriteCommandAction.runWriteCommandAction(project, () -> {
|
||||
try {
|
||||
file.setBinaryContent(text.getBytes());
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException("二进制文件写入失败,fileName:" + fileName);
|
||||
}
|
||||
});
|
||||
return fileDocumentManager.getDocument(file);
|
||||
}
|
||||
WriteCommandAction.runWriteCommandAction(project, () -> document.setText(text));
|
||||
PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(project);
|
||||
|
|
Loading…
Reference in New Issue