当前位置: 首页>>代码示例>>Java>>正文


Java FoldRegion类代码示例

本文整理汇总了Java中com.intellij.openapi.editor.FoldRegion的典型用法代码示例。如果您正苦于以下问题:Java FoldRegion类的具体用法?Java FoldRegion怎么用?Java FoldRegion使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


FoldRegion类属于com.intellij.openapi.editor包,在下文中一共展示了FoldRegion类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: fold

import com.intellij.openapi.editor.FoldRegion; //导入依赖的package包/类
/**
 * 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);
    }
  });
}
 
开发者ID:healarconr,项目名称:logger-folding,代码行数:24,代码来源:FoldLoggerMethodCallsAction.java

示例2: testFoldingIsNotBlinkingOnNavigationToSingleLineMethod

import com.intellij.openapi.editor.FoldRegion; //导入依赖的package包/类
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());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:JavaFileEditorManagerTest.java

示例3: testUnexpectedClassLevelJavadocExpandingOnClassSignatureChange

import com.intellij.openapi.editor.FoldRegion; //导入依赖的package包/类
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());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:FoldingProcessingOnDocumentModificationTest.java

示例4: createRange

import com.intellij.openapi.editor.FoldRegion; //导入依赖的package包/类
@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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:FoldingModelSupport.java

示例5: getLineConvertor

import com.intellij.openapi.editor.FoldRegion; //导入依赖的package包/类
@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;
    }
  };
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:FoldingModelSupport.java

示例6: expandAll

import com.intellij.openapi.editor.FoldRegion; //导入依赖的package包/类
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;
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:FoldingModelSupport.java

示例7: getHighlighterCondition

import com.intellij.openapi.editor.FoldRegion; //导入依赖的package包/类
@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;
    }
  };
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:FoldingModelSupport.java

示例8: advancePositionOnFolding

import com.intellij.openapi.editor.FoldRegion; //导入依赖的package包/类
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);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:AbstractMappingStrategy.java

示例9: getFoldingData

import com.intellij.openapi.editor.FoldRegion; //导入依赖的package包/类
@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();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:CacheEntry.java

示例10: advance

import com.intellij.openapi.editor.FoldRegion; //导入依赖的package包/类
@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();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:FoldingDataProvider.java

示例11: processFoldRegion

import com.intellij.openapi.editor.FoldRegion; //导入依赖的package包/类
@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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:LogicalToOffsetCalculationStrategy.java

示例12: tryAdding

import com.intellij.openapi.editor.FoldRegion; //导入依赖的package包/类
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));
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:FoldingAnchorsOverlayStrategy.java

示例13: testOccurrenceInCollapsedRegion

import com.intellij.openapi.editor.FoldRegion; //导入依赖的package包/类
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());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:SelectUnselectOccurrenceActionsTest.java

示例14: testPrevNextWordWithFolding

import com.intellij.openapi.editor.FoldRegion; //导入依赖的package包/类
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());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:NextPrevWordTest.java

示例15: testPrevNextWordWithSelectionAndFolding

import com.intellij.openapi.editor.FoldRegion; //导入依赖的package包/类
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());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:NextPrevWordTest.java


注:本文中的com.intellij.openapi.editor.FoldRegion类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。