use of com.intellij.openapi.fileEditor.impl.text.CodeFoldingState in project intellij-community by JetBrains.
the class CodeFoldingManagerImpl method buildInitialFoldings.
@Override
public void buildInitialFoldings(@NotNull final Editor editor) {
final Project project = editor.getProject();
if (project == null || !project.equals(myProject) || editor.isDisposed())
return;
if (!((FoldingModelEx) editor.getFoldingModel()).isFoldingEnabled())
return;
if (!FoldingUpdate.supportsDumbModeFolding(editor))
return;
Document document = editor.getDocument();
PsiDocumentManager.getInstance(myProject).commitDocument(document);
CodeFoldingState foldingState = buildInitialFoldings(document);
if (foldingState != null) {
foldingState.setToEditor(editor);
}
}
use of com.intellij.openapi.fileEditor.impl.text.CodeFoldingState in project intellij-community by JetBrains.
the class CodeFoldingManagerImpl method buildInitialFoldings.
@Nullable
@Override
public CodeFoldingState buildInitialFoldings(@NotNull final Document document) {
if (myProject.isDisposed()) {
return null;
}
ApplicationManager.getApplication().assertReadAccessAllowed();
PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(myProject);
if (psiDocumentManager.isUncommited(document)) {
// skip building foldings for uncommitted document, CodeFoldingPass invoked by daemon will do it later
return null;
}
//Do not save/restore folding for code fragments
final PsiFile file = psiDocumentManager.getPsiFile(document);
if (file == null || !file.isValid() || !file.getViewProvider().isPhysical() && !ApplicationManager.getApplication().isUnitTestMode()) {
return null;
}
final FoldingUpdate.FoldingMap foldingMap = FoldingUpdate.getFoldingsFor(file, document, true);
return editor -> {
ApplicationManagerEx.getApplicationEx().assertIsDispatchThread();
if (myProject.isDisposed() || editor.isDisposed())
return;
final FoldingModelEx foldingModel = (FoldingModelEx) editor.getFoldingModel();
if (!foldingModel.isFoldingEnabled())
return;
if (isFoldingsInitializedInEditor(editor))
return;
if (DumbService.isDumb(myProject) && !FoldingUpdate.supportsDumbModeFolding(editor))
return;
foldingModel.runBatchFoldingOperationDoNotCollapseCaret(new UpdateFoldRegionsOperation(myProject, editor, file, foldingMap, UpdateFoldRegionsOperation.ApplyDefaultStateMode.YES, false, false));
initFolding(editor);
};
}
Aggregations