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");
}
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;
}
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);
}
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()]);
}
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));
}
}
Aggregations