Search in sources :

Example 46 with FoldRegion

use of com.intellij.openapi.editor.FoldRegion in project intellij-community by JetBrains.

the class VisualLineFragmentsIterator method init.

private void init(EditorView view, int startOffset, int startLogicalLine, int currentOrPrevWrapIndex, int nextFoldingIndex, @Nullable Runnable quickEvaluationListener) {
    myQuickEvaluationListener = quickEvaluationListener;
    myView = view;
    EditorImpl editor = view.getEditor();
    myDocument = editor.getDocument();
    FoldingModelEx foldingModel = editor.getFoldingModel();
    FoldRegion[] regions = foldingModel.fetchTopLevel();
    myRegions = regions == null ? FoldRegion.EMPTY_ARRAY : regions;
    SoftWrapModelImpl softWrapModel = editor.getSoftWrapModel();
    List<? extends SoftWrap> softWraps = softWrapModel.getRegisteredSoftWraps();
    SoftWrap currentOrPrevWrap = currentOrPrevWrapIndex < 0 || currentOrPrevWrapIndex >= softWraps.size() ? null : softWraps.get(currentOrPrevWrapIndex);
    SoftWrap followingWrap = (currentOrPrevWrapIndex + 1) < 0 || (currentOrPrevWrapIndex + 1) >= softWraps.size() ? null : softWraps.get(currentOrPrevWrapIndex + 1);
    myVisualLineStartOffset = mySegmentStartOffset = startOffset;
    myCurrentFoldRegionIndex = nextFoldingIndex;
    myCurrentEndLogicalLine = startLogicalLine;
    myCurrentX = myView.getInsets().left;
    if (mySegmentStartOffset == 0) {
        myCurrentX += myView.getPrefixTextWidthInPixels();
    } else if (currentOrPrevWrap != null && mySegmentStartOffset == currentOrPrevWrap.getStart()) {
        myCurrentX += currentOrPrevWrap.getIndentInPixels();
        myCurrentVisualColumn = currentOrPrevWrap.getIndentInColumns();
    }
    myNextWrapOffset = followingWrap == null ? Integer.MAX_VALUE : followingWrap.getStart();
    setInlaysAndFragmentIterator();
}
Also used : EditorImpl(com.intellij.openapi.editor.impl.EditorImpl) FoldRegion(com.intellij.openapi.editor.FoldRegion) SoftWrapModelImpl(com.intellij.openapi.editor.impl.SoftWrapModelImpl) SoftWrap(com.intellij.openapi.editor.SoftWrap) FoldingModelEx(com.intellij.openapi.editor.ex.FoldingModelEx)

Example 47 with FoldRegion

use of com.intellij.openapi.editor.FoldRegion in project intellij-community by JetBrains.

the class PyConsoleStartFolding method addFolding.

private void addFolding(DocumentEvent event) {
    Document document = myConsoleView.getEditor().getDocument();
    if (doNotAddFoldingAgain || document.getTextLength() == 0) {
        return;
    }
    if (myNumberOfCommandExecuted >= myNumberOfCommandToStop) {
        document.removeDocumentListener(this);
        return;
    }
    FoldingModel foldingModel = myConsoleView.getEditor().getFoldingModel();
    foldingModel.runBatchFoldingOperation(() -> {
        int start = myStartLineOffset;
        int finish = document.getTextLength() - 1;
        String placeholderText = DEFAULT_FOLDING_MESSAGE;
        int firstLine = document.getLineNumber(myStartLineOffset);
        for (int line = firstLine; line < document.getLineCount(); line++) {
            String lineText = document.getText(DocumentUtil.getLineTextRange(document, line));
            if (lineText.startsWith("Python")) {
                if (start == myStartLineOffset) {
                    start = document.getLineStartOffset(line);
                }
                placeholderText = lineText;
                break;
            }
            if (lineText.startsWith("PyDev console")) {
                start = document.getLineStartOffset(line);
            }
        }
        String newFragment = event.getNewFragment().toString();
        if (newFragment.startsWith("In[") || newFragment.startsWith(PyConsoleUtil.ORDINARY_PROMPT)) {
            finish = event.getOffset() - 1;
            doNotAddFoldingAgain = true;
        }
        if (myStartFoldRegion != null) {
            foldingModel.removeFoldRegion(myStartFoldRegion);
        }
        FoldRegion foldRegion = foldingModel.addFoldRegion(start, finish, placeholderText);
        if (foldRegion != null) {
            foldRegion.setExpanded(false);
            myStartFoldRegion = foldRegion;
        }
    });
}
Also used : FoldingModel(com.intellij.openapi.editor.FoldingModel) FoldRegion(com.intellij.openapi.editor.FoldRegion) Document(com.intellij.openapi.editor.Document)

Aggregations

FoldRegion (com.intellij.openapi.editor.FoldRegion)47 TextRange (com.intellij.openapi.util.TextRange)7 ArrayList (java.util.ArrayList)7 FoldingModel (com.intellij.openapi.editor.FoldingModel)6 NotNull (org.jetbrains.annotations.NotNull)6 FoldingGroup (com.intellij.openapi.editor.FoldingGroup)5 FoldingModelEx (com.intellij.openapi.editor.ex.FoldingModelEx)5 PsiElement (com.intellij.psi.PsiElement)5 CodeFoldingManager (com.intellij.codeInsight.folding.CodeFoldingManager)3 FoldingDescriptor (com.intellij.lang.folding.FoldingDescriptor)3 Document (com.intellij.openapi.editor.Document)3 Editor (com.intellij.openapi.editor.Editor)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 Nullable (org.jetbrains.annotations.Nullable)3 LogicalPosition (com.intellij.openapi.editor.LogicalPosition)2 RangeMarker (com.intellij.openapi.editor.RangeMarker)2 SoftWrap (com.intellij.openapi.editor.SoftWrap)2 DocumentEx (com.intellij.openapi.editor.ex.DocumentEx)2 Project (com.intellij.openapi.project.Project)2 PsiFile (com.intellij.psi.PsiFile)2