Java Code Examples for com.intellij.openapi.editor.FoldRegion#setExpanded()
The following examples show how to use
com.intellij.openapi.editor.FoldRegion#setExpanded() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FoldingModelSupport.java From consulo with Apache License 2.0 | 6 votes |
@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; }
Example 2
Source File: CollapseExpandDocCommentsHandler.java From consulo with Apache License 2.0 | 6 votes |
@RequiredWriteAction @Override public void invokeInWriteAction(@Nonnull Project project, @Nonnull final Editor editor, @Nonnull PsiFile file){ PsiDocumentManager.getInstance(project).commitAllDocuments(); CodeFoldingManager foldingManager = CodeFoldingManager.getInstance(project); foldingManager.updateFoldRegions(editor); final FoldRegion[] allFoldRegions = editor.getFoldingModel().getAllFoldRegions(); Runnable processor = new Runnable() { @Override public void run() { for (FoldRegion region : allFoldRegions) { PsiElement element = EditorFoldingInfo.get(editor).getPsiElement(region); if (element instanceof PsiDocCommentBase) { region.setExpanded(myExpand); } } } }; editor.getFoldingModel().runBatchFoldingOperation(processor); }
Example 3
Source File: ExpandRegionAction.java From consulo with Apache License 2.0 | 6 votes |
public static void expandRegionAtOffset(@Nonnull Project project, @Nonnull final Editor editor, final int offset) { CodeFoldingManager foldingManager = CodeFoldingManager.getInstance(project); foldingManager.updateFoldRegions(editor); final int line = editor.getDocument().getLineNumber(offset); Runnable processor = () -> { FoldRegion region = FoldingUtil.findFoldRegionStartingAtLine(editor, line); if (region != null && !region.isExpanded()) { region.setExpanded(true); } else { FoldRegion[] regions = FoldingUtil.getFoldRegionsAtOffset(editor, offset); for (int i = regions.length - 1; i >= 0; i--) { region = regions[i]; if (!region.isExpanded()) { region.setExpanded(true); break; } } } }; editor.getFoldingModel().runBatchFoldingOperation(processor); }
Example 4
Source File: FoldingModelSupport.java From consulo with Apache License 2.0 | 5 votes |
@Nullable private static FoldRegion addFolding(@Nonnull 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); value.setInnerHighlightersMuted(true); } return value; }
Example 5
Source File: UpdateFoldRegionsOperation.java From consulo with Apache License 2.0 | 5 votes |
private static void applyExpandStatus(@Nonnull List<? extends FoldRegion> newRegions, @Nonnull Map<FoldRegion, Boolean> shouldExpand, @Nonnull Map<FoldingGroup, Boolean> groupExpand) { for (final FoldRegion region : newRegions) { final FoldingGroup group = region.getGroup(); final Boolean expanded = group == null ? shouldExpand.get(region) : groupExpand.get(group); if (expanded != null) { region.setExpanded(expanded.booleanValue()); } } }
Example 6
Source File: CollapseRegionAction.java From consulo with Apache License 2.0 | 5 votes |
public CollapseRegionAction() { super(new BaseFoldingHandler() { @Override public void doExecute(@Nonnull final Editor editor, @Nullable Caret caret, DataContext dataContext) { CodeFoldingManager foldingManager = CodeFoldingManager.getInstance(editor.getProject()); foldingManager.updateFoldRegions(editor); final int line = editor.getCaretModel().getLogicalPosition().line; Runnable processor = () -> { FoldRegion region = FoldingUtil.findFoldRegionStartingAtLine(editor, line); if (region != null && region.isExpanded()) { region.setExpanded(false); } else { int offset = editor.getCaretModel().getOffset(); FoldRegion[] regions = FoldingUtil.getFoldRegionsAtOffset(editor, offset); for (FoldRegion region1 : regions) { if (region1.isExpanded()) { region1.setExpanded(false); break; } } } }; editor.getFoldingModel().runBatchFoldingOperation(processor); } }); }