use of com.intellij.openapi.editor.FoldRegion in project intellij-community by JetBrains.
the class FoldingUtilTest method testFoldTreeIterator.
public void testFoldTreeIterator() {
configureFromFileText(getTestName(false) + ".txt", "abcdefghijklmnopqrstuvwxyz");
EditorTestUtil.addFoldRegion(myEditor, 0, 10, ".", true);
EditorTestUtil.addFoldRegion(myEditor, 0, 5, ".", false);
EditorTestUtil.addFoldRegion(myEditor, 1, 2, ".", true);
EditorTestUtil.addFoldRegion(myEditor, 7, 10, ".", false);
EditorTestUtil.addFoldRegion(myEditor, 10, 11, ".", true);
StringBuilder b = new StringBuilder();
Iterator<FoldRegion> it = FoldingUtil.createFoldTreeIterator(myEditor);
while (it.hasNext()) {
FoldRegion region = it.next();
if (b.length() > 0) {
b.append('|');
}
b.append(region.getStartOffset()).append(',').append(region.getEndOffset());
}
assertEquals("0,10|0,5|1,2|7,10|10,11", b.toString());
}
use of com.intellij.openapi.editor.FoldRegion in project intellij-community by JetBrains.
the class BlockSelectionEditingTest method testBlockRemovalAndCollapsedFoldRegionsBefore.
public void testBlockRemovalAndCollapsedFoldRegionsBefore() throws IOException {
// Inspired by IDEA-69371
String initialText = "fold line #1\n" + "fold line #2\n" + "initialText line 1\n" + "initialText line 2\n" + "initialText line 3";
init(initialText, TestFileType.TEXT);
final int foldEndOffset = initialText.indexOf("initialText");
addCollapsedFoldRegion(0, foldEndOffset, "...");
int column = "initialText".length();
final LogicalPosition blockStart = new LogicalPosition(3, column);
final LogicalPosition blockEnd = new LogicalPosition(4, column);
final SelectionModel selectionModel = myEditor.getSelectionModel();
selectionModel.setBlockSelection(blockStart, blockEnd);
delete();
delete();
String expectedText = "fold line #1\n" + "fold line #2\n" + "initialText line 1\n" + "initialText line 2\n" + "initialText line 3";
assertEquals(expectedText, myEditor.getDocument().getText());
assertSelectionRanges(new int[][] { { 59, 59 }, { 79, 79 } });
final FoldRegion foldRegion = getFoldRegion(0);
assertNotNull(foldRegion);
assertEquals(0, foldRegion.getStartOffset());
assertEquals(foldEndOffset, foldRegion.getEndOffset());
}
use of com.intellij.openapi.editor.FoldRegion in project intellij-community by JetBrains.
the class FoldingTransformation method findFoldRegion.
private FoldRegion findFoldRegion(int line) {
int index = Arrays.binarySearch(myFoldBeginings, line);
FoldRegion region;
if (index >= 0)
region = myCollapsed.get(index);
else {
index = -index - 1;
if (index == 0)
return null;
region = myCollapsed.get(index - 1);
}
if (getEndLine(region) < line)
return null;
return region;
}
use of com.intellij.openapi.editor.FoldRegion in project intellij-community by JetBrains.
the class FoldingTransformation method transform.
public int transform(int line) {
FoldRegion foldRegion = findFoldRegion(line);
int yOffset = 0;
if (foldRegion != null) {
int startLine = getStartLine(foldRegion);
yOffset = (int) ((double) (line - startLine) / getLineLength(foldRegion) * myEditor.getLineHeight());
line = startLine;
}
yOffset += myEditor.logicalPositionToXY(new LogicalPosition(line, 0)).y;
final JComponent header = myEditor.getHeaderComponent();
int headerOffset = header == null ? 0 : header.getHeight();
return yOffset - myEditor.getScrollingModel().getVerticalScrollOffset() + headerOffset;
}
use of com.intellij.openapi.editor.FoldRegion in project intellij-community by JetBrains.
the class FoldingAnchorsOverlayStrategy method getAnchorsToDisplay.
@NotNull
Collection<DisplayedFoldingAnchor> getAnchorsToDisplay(int firstVisibleOffset, int lastVisibleOffset, FoldRegion activeFoldRegion) {
Map<Integer, DisplayedFoldingAnchor> result = new HashMap<>();
FoldRegion[] visibleFoldRegions = myEditor.getFoldingModel().fetchVisible();
for (FoldRegion region : visibleFoldRegions) {
if (!region.isValid())
continue;
final int startOffset = region.getStartOffset();
if (startOffset > lastVisibleOffset)
continue;
final int endOffset = getEndOffset(region);
if (endOffset < firstVisibleOffset)
continue;
if (!isFoldingPossible(startOffset, endOffset))
continue;
final FoldingGroup group = region.getGroup();
if (group != null && myEditor.getFoldingModel().getFirstRegion(group, region) != region)
continue;
//offset = Math.min(myEditor.getDocument().getTextLength() - 1, offset);
int foldStart = myEditor.offsetToVisualLine(startOffset);
if (!region.isExpanded()) {
tryAdding(result, region, foldStart, 0, DisplayedFoldingAnchor.Type.COLLAPSED, activeFoldRegion);
} else {
//offset = Math.min(myEditor.getDocument().getTextLength() - 1, offset);
int foldEnd = myEditor.offsetToVisualLine(endOffset);
tryAdding(result, region, foldStart, foldEnd - foldStart, DisplayedFoldingAnchor.Type.EXPANDED_TOP, activeFoldRegion);
tryAdding(result, region, foldEnd, foldEnd - foldStart, DisplayedFoldingAnchor.Type.EXPANDED_BOTTOM, activeFoldRegion);
}
}
return result.values();
}
Aggregations