Search in sources :

Example 36 with FoldRegion

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

the class JavaMoveLineTest method testMoveThroughFolding.

public void testMoveThroughFolding() throws Exception {
    configureByFile(BASE_PATH + "/" + getTestName(false) + ".java");
    CodeFoldingManager.getInstance(ourProject).buildInitialFoldings(myEditor);
    FoldRegion lambdaStart = myEditor.getFoldingModel().getFoldRegion(140, 227);
    assertNotNull(lambdaStart);
    assertFalse(lambdaStart.isExpanded());
    FoldRegion lambdaEnd = myEditor.getFoldingModel().getFoldRegion(248, 272);
    assertNotNull(lambdaEnd);
    assertFalse(lambdaEnd.isExpanded());
    executeAction(IdeActions.ACTION_MOVE_LINE_UP_ACTION);
    checkResultByFile(BASE_PATH + "/" + getTestName(false) + "-after.java");
}
Also used : FoldRegion(com.intellij.openapi.editor.FoldRegion)

Example 37 with FoldRegion

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

the class FoldingModelWindow method createFoldRegion.

@Override
public FoldRegion createFoldRegion(int startOffset, int endOffset, @NotNull String placeholder, FoldingGroup group, boolean neverExpands) {
    TextRange hostRange = myDocumentWindow.injectedToHost(new TextRange(startOffset, endOffset));
    if (hostRange.getLength() < 2)
        return null;
    FoldRegion hostRegion = myDelegate.createFoldRegion(hostRange.getStartOffset(), hostRange.getEndOffset(), placeholder, group, neverExpands);
    int startShift = Math.max(0, myDocumentWindow.hostToInjected(hostRange.getStartOffset()) - startOffset);
    int endShift = Math.max(0, endOffset - myDocumentWindow.hostToInjected(hostRange.getEndOffset()) - startShift);
    FoldingRegionWindow window = new FoldingRegionWindow(myDocumentWindow, myEditorWindow, hostRegion, startShift, endShift);
    hostRegion.putUserData(FOLD_REGION_WINDOW, window);
    return window;
}
Also used : FoldRegion(com.intellij.openapi.editor.FoldRegion) TextRange(com.intellij.openapi.util.TextRange)

Example 38 with FoldRegion

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

the class FoldingModelWindow method getFoldRegion.

@Nullable
@Override
public FoldRegion getFoldRegion(int startOffset, int endOffset) {
    TextRange range = new TextRange(startOffset, endOffset);
    TextRange hostRange = myDocumentWindow.injectedToHost(range);
    FoldRegion hostRegion = myDelegate.getFoldRegion(hostRange.getStartOffset(), hostRange.getEndOffset());
    return hostRegion == null ? null : getWindowRegion(hostRegion);
}
Also used : FoldRegion(com.intellij.openapi.editor.FoldRegion) TextRange(com.intellij.openapi.util.TextRange) Nullable(org.jetbrains.annotations.Nullable)

Example 39 with FoldRegion

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

the class FoldingModelWindow method getAllFoldRegions.

@Override
@NotNull
public FoldRegion[] getAllFoldRegions() {
    FoldRegion[] all = myDelegate.getAllFoldRegions();
    List<FoldRegion> result = new ArrayList<>();
    for (FoldRegion region : all) {
        FoldingRegionWindow window = getWindowRegion(region);
        if (window != null) {
            result.add(window);
        }
    }
    return result.toArray(new FoldRegion[result.size()]);
}
Also used : ArrayList(java.util.ArrayList) FoldRegion(com.intellij.openapi.editor.FoldRegion) NotNull(org.jetbrains.annotations.NotNull)

Example 40 with FoldRegion

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

the class AbstractFoldingPolicyTest method doTest.

protected void doTest(@NotNull String text, @NotNull String ext) {
    myFixture.configureByText("test." + ext, text);
    CodeFoldingManager.getInstance(getProject()).buildInitialFoldings(myFixture.getEditor());
    EditorFoldingInfo info = EditorFoldingInfo.get(myFixture.getEditor());
    FoldRegion[] foldRegions = myFixture.getEditor().getFoldingModel().getAllFoldRegions();
    assertTrue(foldRegions.length > 0);
    for (FoldRegion region : foldRegions) {
        PsiElement element = info.getPsiElement(region);
        if (element == null) {
            continue;
        }
        String signature = FoldingPolicy.getSignature(element);
        assertNotNull(signature);
        assertEquals(element, FoldingPolicy.restoreBySignature(element.getContainingFile(), signature));
    }
}
Also used : FoldRegion(com.intellij.openapi.editor.FoldRegion) PsiElement(com.intellij.psi.PsiElement)

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