/** * Runs a batch folding operation that folds the given text range * * @param editor the editor to get the folding model * @param textRange the text range to fold * @param placeholderText the fold region placeholder text */ private void fold(@NotNull final Editor editor, @NotNull final TextRange textRange, @NotNull final String placeholderText) { editor.getFoldingModel().runBatchFoldingOperation(() -> { FoldRegion foldRegion = editor.getFoldingModel() .getFoldRegion(textRange.getStartOffset(), textRange.getEndOffset()); if (foldRegion == null) { foldRegion = editor.getFoldingModel() .addFoldRegion(textRange.getStartOffset(), textRange.getEndOffset(), placeholderText); } if (foldRegion != null) { foldRegion.setExpanded(false); } }); }
public void testFoldingIsNotBlinkingOnNavigationToSingleLineMethod() { VirtualFile file = getFile("/src/Bar.java"); PsiJavaFile psiFile = (PsiJavaFile)getPsiManager().findFile(file); assertNotNull(psiFile); PsiMethod method = psiFile.getClasses()[0].getMethods()[0]; method.navigate(true); FileEditor[] editors = myManager.getEditors(file); assertEquals(1, editors.length); Editor editor = ((TextEditor)editors[0]).getEditor(); FoldRegion[] regions = editor.getFoldingModel().getAllFoldRegions(); assertEquals(2, regions.length); assertTrue(regions[0].isExpanded()); assertTrue(regions[1].isExpanded()); CodeInsightTestFixtureImpl.instantiateAndRun(psiFile, editor, new int[]{Pass.UPDATE_ALL, Pass.LOCAL_INSPECTIONS}, false); regions = editor.getFoldingModel().getAllFoldRegions(); assertEquals(2, regions.length); assertTrue(regions[0].isExpanded()); assertTrue(regions[1].isExpanded()); }
public void testUnexpectedClassLevelJavadocExpandingOnClassSignatureChange() throws IOException { // Inspired by IDEA-61275 String text = "/**\n" + " * This is a test comment\n" + " */\n" + "public <caret>class Test {\n" + "}"; init(text, TestFileType.JAVA); CaretModel caretModel = myEditor.getCaretModel(); int caretOffset = caretModel.getOffset(); assertEquals(caretOffset, caretModel.getOffset()); updateFoldRegions(); toggleFoldRegionState(getFoldRegion(0), false); type('a'); updateFoldRegions(); assertEquals(caretOffset + 1, caretModel.getOffset()); assertEquals(1, myEditor.getFoldingModel().getAllFoldRegions().length); FoldRegion foldRegion = getFoldRegion(0); assertFalse(foldRegion.isExpanded()); }
@Nullable private FoldedBlock createRange(int[] starts, int[] ends, boolean expanded) { boolean hasFolding = false; FoldRegion[] regions = new FoldRegion[myCount]; boolean hasExpanded = false; // do not desync on runBatchFoldingOperationDoNotCollapseCaret for (int i = 0; i < myCount; i++) { if (ends[i] - starts[i] < 2) continue; regions[i] = addFolding(myEditors[i], starts[i], ends[i], expanded); hasFolding |= regions[i] != null; hasExpanded |= regions[i] != null && regions[i].isExpanded(); } if (hasExpanded && !expanded) { for (FoldRegion region : regions) { if (region != null) region.setExpanded(true); } } return hasFolding ? new FoldedBlock(regions) : null; }
@NotNull protected TIntFunction getLineConvertor(final int index) { return new TIntFunction() { @Override public int execute(int value) { updateLineNumbers(false); for (FoldedBlock folding : getFoldedBlocks()) { // TODO: avoid full scan - it could slowdown painting int line = folding.getLine(index); if (line == -1) continue; if (line > value) break; FoldRegion region = folding.getRegion(index); if (line == value && region != null && !region.isExpanded()) return -1; } return value; } }; }
public void expandAll(final boolean expanded) { if (myDuringSynchronize) return; myDuringSynchronize = true; try { for (int i = 0; i < myCount; i++) { final int index = i; final FoldingModelEx model = myEditors[index].getFoldingModel(); model.runBatchFoldingOperation(new Runnable() { @Override public void run() { for (FoldedBlock folding : getFoldedBlocks()) { FoldRegion region = folding.getRegion(index); if (region != null) region.setExpanded(expanded); } } }); } } finally { myDuringSynchronize = false; } }
@NotNull private BooleanGetter getHighlighterCondition(@NotNull final FoldedBlock[] block, final int index) { return new BooleanGetter() { @Override public boolean get() { if (!myEditors[index].getFoldingModel().isFoldingEnabled()) return false; for (FoldedBlock folding : block) { FoldRegion region = folding.getRegion(index); boolean visible = region != null && region.isValid() && !region.isExpanded(); if (folding == FoldedBlock.this) return visible; if (visible) return false; // do not paint separator, if 'parent' folding is collapsed } return false; } }; }
protected void advancePositionOnFolding(@NotNull EditorPosition position, @NotNull FoldRegion foldRegion) { Document document = myEditor.getDocument(); int endOffsetLogicalLine = document.getLineNumber(foldRegion.getEndOffset()); if (position.logicalLine != endOffsetLogicalLine) { // Multi-line fold region. position.softWrapColumnDiff = 0; position.softWrapLinesBefore += position.softWrapLinesCurrent; position.softWrapLinesCurrent = 0; } int collapsedSymbolsWidthInColumns = -1; FoldingData foldingData = getFoldRegionData(foldRegion); if (foldingData != null) { collapsedSymbolsWidthInColumns = foldingData.getCollapsedSymbolsWidthInColumns(); } position.advance(foldRegion, collapsedSymbolsWidthInColumns); }
@Nullable public FoldingData getFoldingData(@NotNull final FoldRegion region) { FoldingData candidate = myFoldingData.get(region.getStartOffset()); if (candidate != null) { return candidate; } // Folding implementation is known to postpone actual fold region offsets update on document change, i.e. it performs // fold data caching with its further replace by up-to-date info. Hence, there is a possible case that soft wraps processing // advances fold region offset but folding model still provides old cached values. Hence, we're trying to match exact given // fold region against the cached data here. final Ref<FoldingData> result = new Ref<FoldingData>(); myFoldingData.forEachValue(new TObjectProcedure<FoldingData>() { @Override public boolean execute(FoldingData data) { if (data.getFoldRegion().equals(region)) { result.set(data); return false; } return true; } }); return result.get(); }
@Override public void advance(int sortingKey) { // We inline binary search here because profiling indicates that as a performance boost. int start = myIndex; int end = myFoldRegions.length - 1; // We inline binary search here because profiling indicates that it becomes bottleneck to use Collections.binarySearch(). while (start <= end) { int i = (end + start) >>> 1; FoldRegion foldRegion = myFoldRegions[i]; if (foldRegion.getStartOffset() < sortingKey) { start = i + 1; continue; } if (foldRegion.getStartOffset() > sortingKey) { end = i - 1; continue; } myIndex = i; scrollToInterested(); return; } myIndex = start; scrollToInterested(); }
@Override public Integer processFoldRegion(@NotNull EditorPosition position, @NotNull FoldRegion foldRegion) { int startLine = position.logicalLine; int startColumn = position.logicalColumn; int startX = position.x; advancePositionOnFolding(position, foldRegion); if (position.logicalLine < targetPosition.line || position.logicalLine == targetPosition.line && position.logicalColumn <= targetPosition.column) { return null; } Document document = myEditor.getDocument(); int lineEndOffset = document.getLineEndOffset(targetPosition.line); int result = SoftWrapModelImpl.getEditorTextRepresentationHelper(myEditor) .calcSoftWrapUnawareOffset(targetPosition.line == startLine ? foldRegion.getStartOffset() : document.getLineStartOffset(targetPosition.line), lineEndOffset, targetPosition.line == startLine ? startColumn : 0, targetPosition.column, targetPosition.line == startLine ? startX : 0); return result < 0 ? lineEndOffset : result; }
private static void tryAdding(Map<Integer, DisplayedFoldingAnchor> resultsMap, FoldRegion region, int visualLine, int visualHeight, DisplayedFoldingAnchor.Type type, FoldRegion activeRegion) { DisplayedFoldingAnchor prev = resultsMap.get(visualLine); if (prev != null) { if (prev.foldRegion == activeRegion) { return; } if (region != activeRegion && prev.foldRegionVisualLines < visualHeight) { return; } } resultsMap.put(visualLine, new DisplayedFoldingAnchor(region, visualLine, visualHeight, type)); }
public void testOccurrenceInCollapsedRegion() throws Exception { init("normal <selection><caret>line</selection>\n" + "collapsed line"); final FoldingModel foldingModel = myFixture.getEditor().getFoldingModel(); final Document document = myFixture.getEditor().getDocument(); foldingModel.runBatchFoldingOperation(new Runnable() { @Override public void run() { FoldRegion foldRegion = foldingModel.addFoldRegion(document.getLineStartOffset(1), document.getLineEndOffset(1), "..."); assertNotNull(foldRegion); foldRegion.setExpanded(false); } }); executeAction(); checkResult("normal <selection><caret>line</selection>\n" + "collapsed <selection><caret>line</selection>"); FoldRegion[] foldRegions = foldingModel.getAllFoldRegions(); assertEquals(1, foldRegions.length); assertTrue(foldRegions[0].isExpanded()); }
public void testPrevNextWordWithFolding() { myFixture.configureByText("a.txt", "<caret>brown fox"); EditorTestUtil.addFoldRegion(myFixture.getEditor(), 4, 7, "...", true); myFixture.performEditorAction(IdeActions.ACTION_EDITOR_NEXT_WORD); myFixture.checkResult("brow<caret>n fox"); myFixture.performEditorAction(IdeActions.ACTION_EDITOR_NEXT_WORD); myFixture.checkResult("brown f<caret>ox"); myFixture.performEditorAction(IdeActions.ACTION_EDITOR_NEXT_WORD); myFixture.checkResult("brown fox<caret>"); myFixture.performEditorAction(IdeActions.ACTION_EDITOR_PREVIOUS_WORD); myFixture.checkResult("brown f<caret>ox"); myFixture.performEditorAction(IdeActions.ACTION_EDITOR_PREVIOUS_WORD); myFixture.checkResult("brow<caret>n fox"); myFixture.performEditorAction(IdeActions.ACTION_EDITOR_PREVIOUS_WORD); myFixture.checkResult("<caret>brown fox"); FoldRegion[] foldRegions = myFixture.getEditor().getFoldingModel().getAllFoldRegions(); assertEquals(1, foldRegions.length); assertFalse(foldRegions[0].isExpanded()); }
public void testPrevNextWordWithSelectionAndFolding() { myFixture.configureByText("a.txt", "<caret>brown fox"); EditorTestUtil.addFoldRegion(myFixture.getEditor(), 4, 7, "...", true); myFixture.performEditorAction(IdeActions.ACTION_EDITOR_NEXT_WORD_WITH_SELECTION); myFixture.checkResult("<selection>brow<caret></selection>n fox"); myFixture.performEditorAction(IdeActions.ACTION_EDITOR_NEXT_WORD_WITH_SELECTION); myFixture.checkResult("<selection>brown f<caret></selection>ox"); myFixture.performEditorAction(IdeActions.ACTION_EDITOR_NEXT_WORD_WITH_SELECTION); myFixture.checkResult("<selection>brown fox<caret></selection>"); myFixture.performEditorAction(IdeActions.ACTION_EDITOR_PREVIOUS_WORD_WITH_SELECTION); myFixture.checkResult("<selection>brown f<caret></selection>ox"); myFixture.performEditorAction(IdeActions.ACTION_EDITOR_PREVIOUS_WORD_WITH_SELECTION); myFixture.checkResult("<selection>brow<caret></selection>n fox"); myFixture.performEditorAction(IdeActions.ACTION_EDITOR_PREVIOUS_WORD_WITH_SELECTION); myFixture.checkResult("<caret>brown fox"); FoldRegion[] foldRegions = myFixture.getEditor().getFoldingModel().getAllFoldRegions(); assertEquals(1, foldRegions.length); assertFalse(foldRegions[0].isExpanded()); }
private void verifyAnchors(FoldRegion activeFoldRegion, Object... expectedAnchorParameters) { Collection<DisplayedFoldingAnchor> actualAnchors = new FoldingAnchorsOverlayStrategy((EditorImpl)myFixture.getEditor()) .getAnchorsToDisplay(0, myFixture.getEditor().getDocument().getTextLength(), activeFoldRegion); List<DisplayedFoldingAnchor> sortedActualAnchors = new ArrayList<DisplayedFoldingAnchor>(actualAnchors); Collections.sort(sortedActualAnchors, new Comparator<DisplayedFoldingAnchor>() { @Override public int compare(DisplayedFoldingAnchor o1, DisplayedFoldingAnchor o2) { return o1.visualLine - o2.visualLine; } }); assertEquals("Wrong number of anchors", expectedAnchorParameters.length / 2, sortedActualAnchors.size()); int i = 0; for (DisplayedFoldingAnchor anchor : sortedActualAnchors) { int expectedVisualLine = (Integer) expectedAnchorParameters[i++]; assertEquals("Folding anchor at wrong line found", expectedVisualLine, anchor.visualLine); Type expectedType = (Type)expectedAnchorParameters[i++]; assertEquals("Folding anchor of wrong type found at line " + expectedVisualLine, expectedType, anchor.type); } }
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)); } }
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()); }
@NotNull @Override public List<FoldingTransferableData> collectTransferableData(final PsiFile file, final Editor editor, final int[] startOffsets, final int[] endOffsets) { // might be slow //CodeFoldingManager.getInstance(file.getManager().getProject()).updateFoldRegions(editor); final ArrayList<FoldingData> list = new ArrayList<FoldingData>(); final FoldRegion[] regions = editor.getFoldingModel().getAllFoldRegions(); for (final FoldRegion region : regions) { if (!region.isValid()) continue; for (int j = 0; j < startOffsets.length; j++) { if (startOffsets[j] <= region.getStartOffset() && region.getEndOffset() <= endOffsets[j]) { list.add( new FoldingData( region.getStartOffset() - startOffsets[j], region.getEndOffset() - startOffsets[j], region.isExpanded() ) ); } } } return Collections.singletonList(new FoldingTransferableData(list.toArray(new FoldingData[list.size()]))); }
@Override public void run() { EditorFoldingInfo info = EditorFoldingInfo.get(myEditor); FoldingModelEx foldingModel = (FoldingModelEx)myEditor.getFoldingModel(); Map<TextRange,Boolean> rangeToExpandStatusMap = newTroveMap(); // FoldingUpdate caches instances of our object, so they must be immutable. FoldingUpdate.FoldingMap elementsToFold = new FoldingUpdate.FoldingMap(myElementsToFoldMap); removeInvalidRegions(info, foldingModel, elementsToFold, rangeToExpandStatusMap); Map<FoldRegion, Boolean> shouldExpand = newTroveMap(); Map<FoldingGroup, Boolean> groupExpand = newTroveMap(); List<FoldRegion> newRegions = addNewRegions(info, foldingModel, elementsToFold, rangeToExpandStatusMap, shouldExpand, groupExpand); applyExpandStatus(newRegions, shouldExpand, groupExpand); }
@Nullable public static FoldRegion findFoldRegionStartingAtLine(@NotNull Editor editor, int line){ if (line < 0 || line >= editor.getDocument().getLineCount()) { return null; } FoldRegion result = null; FoldRegion[] regions = editor.getFoldingModel().getAllFoldRegions(); for (FoldRegion region : regions) { if (!region.isValid()) { continue; } if (region.getDocument().getLineNumber(region.getStartOffset()) == line) { if (result != null) return null; result = region; } } return result; }
/** * Returns fold regions inside selection, or all regions in editor, if selection doesn't exist or doesn't contain fold regions. */ protected List<FoldRegion> getFoldRegionsForSelection(@NotNull Editor editor, @Nullable Caret caret) { FoldRegion[] allRegions = editor.getFoldingModel().getAllFoldRegions(); if (caret == null) { caret = editor.getCaretModel().getPrimaryCaret(); } if (caret.hasSelection()) { List<FoldRegion> result = new ArrayList<FoldRegion>(); for (FoldRegion region : allRegions) { if (region.getStartOffset() >= caret.getSelectionStart() && region.getEndOffset() <= caret.getSelectionEnd()) { result.add(region); } } if (!result.isEmpty()) { return result; } } return Arrays.asList(allRegions); }
public static boolean isEnabled(@NotNull Editor editor) { if (editor.getSelectionModel().hasSelection()) { int start = editor.getSelectionModel().getSelectionStart(); int end = editor.getSelectionModel().getSelectionEnd(); if (start + 1 >= end) { return false; } if (start < end && editor.getDocument().getCharsSequence().charAt(end - 1) == '\n') end--; FoldRegion region = FoldingUtil.findFoldRegion(editor, start, end); if (region == null) { return !((FoldingModelEx) editor.getFoldingModel()).intersectsRegion(start, end); } else { return EditorFoldingInfo.get(editor).getPsiElement(region) == null; } } else { return FoldingUtil.getFoldRegionsAtOffset(editor, editor.getCaretModel().getOffset()).length > 0; } }
private Optional<FoldRegion> getFoldRegionOfMethod(Editor editor, PsiMethod psiMethod) { TextRange textRange = psiMethod.getTextRange(); for (FoldRegion foldRegion : editor.getFoldingModel().getAllFoldRegions()) { if (textRange.getEndOffset() == foldRegion.getEndOffset()) { return Optional.of(foldRegion); } } return Optional.empty(); }
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"); }
@Nullable private static FoldRegion addFolding(@NotNull EditorEx editor, int start, int end, boolean expanded) { DocumentEx document = editor.getDocument(); final int startOffset = document.getLineStartOffset(start); final int endOffset = document.getLineEndOffset(end - 1); FoldRegion value = editor.getFoldingModel().addFoldRegion(startOffset, endOffset, PLACEHOLDER); if (value != null) value.setExpanded(expanded); return value; }
private void destroyFoldings(final int index) { final FoldingModelEx model = myEditors[index].getFoldingModel(); model.runBatchFoldingOperation(new Runnable() { @Override public void run() { for (FoldedBlock folding : getFoldedBlocks()) { FoldRegion region = folding.getRegion(index); if (region != null) model.removeFoldRegion(region); } } }); }
@Override public void onFoldProcessingEnd() { if (myModifiedRegions.isEmpty()) return; myDuringSynchronize = true; try { for (int i = 0; i < myCount; i++) { if (i == myIndex) continue; final int pairedIndex = i; myEditors[pairedIndex].getFoldingModel().runBatchFoldingOperation(new Runnable() { @Override public void run() { for (FoldedBlock folding : getFoldedBlocks()) { FoldRegion region = folding.getRegion(myIndex); if (region == null || !region.isValid()) continue; if (myModifiedRegions.contains(region)) { FoldRegion pairedRegion = folding.getRegion(pairedIndex); if (pairedRegion == null || !pairedRegion.isValid()) continue; pairedRegion.setExpanded(region.isExpanded()); } } } }); } myModifiedRegions.clear(); } finally { myDuringSynchronize = false; } }
@Override public void process(@NotNull Handler handler) { for (FoldedBlock[] block : myFoldings) { for (FoldedBlock folding : block) { FoldRegion region1 = folding.getRegion(myLeft); FoldRegion region2 = folding.getRegion(myRight); if (region1 == null || !region1.isValid() || region1.isExpanded()) continue; if (region2 == null || !region2.isValid() || region2.isExpanded()) continue; int line1 = myEditors[myLeft].getDocument().getLineNumber(region1.getStartOffset()); int line2 = myEditors[myRight].getDocument().getLineNumber(region2.getStartOffset()); if (!handler.process(line1, line2)) return; break; } } }
public FoldingTransformation(Editor editor) { myEditor = editor; FoldRegion[] foldRegions = myEditor.getFoldingModel().getAllFoldRegions(); Arrays.sort(foldRegions, RangeMarker.BY_START_OFFSET); TIntArrayList foldBeginings = new TIntArrayList(); for (FoldRegion foldRegion : foldRegions) { if (!foldRegion.isValid() || foldRegion.isExpanded()) continue; foldBeginings.add(getStartLine(foldRegion)); myCollapsed.add(foldRegion); } myFoldBeginings = foldBeginings.toNativeArray(); }
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; }
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; }
@Nullable public TextRange getPsiElementRange(@NotNull FoldRegion region) { PsiElement element = getPsiElement(region); if (element == null) return null; PsiFile containingFile = element.getContainingFile(); InjectedLanguageManager injectedManager = InjectedLanguageManager.getInstance(containingFile.getProject()); boolean isInjected = injectedManager.isInjectedFragment(containingFile); TextRange range = element.getTextRange(); if (isInjected) { range = injectedManager.injectedToHost(element, range); } return range; }
LineLayout getFoldRegionLayout(FoldRegion foldRegion) { LineLayout layout = foldRegion.getUserData(FOLD_REGION_TEXT_LAYOUT); if (layout == null) { TextAttributes placeholderAttributes = myEditor.getFoldingModel().getPlaceholderAttributes(); layout = new LineLayout(this, foldRegion.getPlaceholderText(), placeholderAttributes == null ? Font.PLAIN : placeholderAttributes.getFontType()); foldRegion.putUserData(FOLD_REGION_TEXT_LAYOUT, layout); } return layout; }
@Override public void onFoldRegionStateChange(@NotNull FoldRegion region) { if (region.isValid()) { foldingChangeStartOffset = Math.min(foldingChangeStartOffset, region.getStartOffset()); foldingChangeEndOffset = Math.max(foldingChangeEndOffset, region.getEndOffset()); } }
private int[] getVisualColumnForXInsideFoldRegion(FoldRegion foldRegion, float x) { LineLayout layout = myView.getFoldRegionLayout(foldRegion); for (LineLayout.VisualFragment fragment : layout.getFragmentsInVisualOrder(0)) { if (x <= fragment.getEndX()) { return fragment.xToVisualColumn(x); } } return new int[] {getFoldRegionWidthInColumns(foldRegion), 1}; }
private float getXForVisualColumnInsideFoldRegion(FoldRegion foldRegion, int column) { LineLayout layout = myView.getFoldRegionLayout(foldRegion); for (LineLayout.VisualFragment fragment : layout.getFragmentsInVisualOrder(0)) { if (column <= fragment.getEndVisualColumn()) { return fragment.visualColumnToX(column); } } return getFoldRegionWidthInPixels(foldRegion); }
@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()); if (hostRegion == null) { return null; } FoldingRegionWindow window = hostRegion.getUserData(FOLD_REGION_WINDOW); return window != null && window.getEditor() == myEditorWindow ? window : null; }
@Override public FoldRegion addFoldRegion(int startOffset, int endOffset, @NotNull String placeholderText) { FoldRegion region = createFoldRegion(startOffset, endOffset, placeholderText, null, false); if (region == null) return null; if (!addFoldRegion(region)) { region.dispose(); return null; } return region; }
private static void doSetExpanded(boolean expanded, FoldingModelImpl foldingModel, FoldRegion region) { if (expanded) { foldingModel.expandFoldRegion(region); } else{ foldingModel.collapseFoldRegion(region); } }