Java Code Examples for com.intellij.openapi.util.TextRange#intersects()

The following examples show how to use com.intellij.openapi.util.TextRange#intersects() . 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: CommentByBlockCommentHandler.java    From consulo with Apache License 2.0 6 votes vote down vote up
private boolean testSelectionForNonComments() {
  if (!myCaret.hasSelection()) {
    return true;
  }
  TextRange range = new TextRange(myCaret.getSelectionStart(), myCaret.getSelectionEnd() - 1);
  for (PsiElement element = myFile.findElementAt(range.getStartOffset()); element != null && range.intersects(element.getTextRange()); element = element.getNextSibling()) {
    if (element instanceof OuterLanguageElement) {
      if (!isInjectedWhiteSpace(range, (OuterLanguageElement)element)) {
        return false;
      }
    }
    else {
      if (!isWhiteSpaceOrComment(element, range)) {
        return false;
      }
    }
  }
  return true;
}
 
Example 2
Source File: ParameterInfoComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public String setupUIComponentPresentation(String text,
                                           int highlightStartOffset,
                                           int highlightEndOffset,
                                           boolean isDisabled,
                                           boolean strikeout,
                                           boolean isDisabledBeforeHighlight,
                                           Color background) {
  List<String> split = StringUtil.split(text, ",", false);
  StringBuilder plainLine = new StringBuilder();
  final List<Integer> startOffsets = new ArrayList<>();
  final List<Integer> endOffsets = new ArrayList<>();

  TextRange highlightRange = highlightStartOffset >= 0 && highlightEndOffset >= highlightStartOffset ? new TextRange(highlightStartOffset, highlightEndOffset) : null;
  for (int j = 0; j < split.size(); j++) {
    String line = split.get(j);
    int startOffset = plainLine.length();
    startOffsets.add(startOffset);
    plainLine.append(line);
    int endOffset = plainLine.length();
    endOffsets.add(endOffset);
    if (highlightRange != null && highlightRange.intersects(new TextRange(startOffset, endOffset))) {
      result.current = j;
    }
  }
  ParameterInfoController.SignatureItem item = new ParameterInfoController.SignatureItem(plainLine.toString(), strikeout, isDisabled, startOffsets, endOffsets);
  result.signatures.add(item);

  final String resultedText = myPanels[i].setup(text, myEscapeFunction, highlightStartOffset, highlightEndOffset, isDisabled, strikeout, isDisabledBeforeHighlight, background);
  myPanels[i].setBorder(isLastParameterOwner() || isSingleParameterInfo() ? EMPTY_BORDER : BOTTOM_BORDER);
  return resultedText;
}
 
Example 3
Source File: UpdateFoldRegionsOperation.java    From consulo with Apache License 2.0 5 votes vote down vote up
private boolean shouldExpandNewRegion(TextRange range, Map<TextRange, Boolean> rangeToExpandStatusMap, boolean collapsedByDefault) {
  if (myApplyDefaultState != ApplyDefaultStateMode.NO) {
    // Considering that this code is executed only on initial fold regions construction on editor opening.
    if (myApplyDefaultState == ApplyDefaultStateMode.EXCEPT_CARET_REGION) {
      TextRange lineRange = OpenFileDescriptor.getRangeToUnfoldOnNavigation(myEditor);
      if (lineRange.intersects(range)) {
        return true;
      }
    }
    return !collapsedByDefault;
  }

  final Boolean oldStatus = rangeToExpandStatusMap.get(range);
  return oldStatus == null || oldStatus.booleanValue() || FoldingUtil.caretInsideRange(myEditor, range);
}
 
Example 4
Source File: LivePreview.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void updateInSelectionHighlighters() {
  final SelectionModel selectionModel = mySearchResults.getEditor().getSelectionModel();
  int[] starts = selectionModel.getBlockSelectionStarts();
  int[] ends = selectionModel.getBlockSelectionEnds();

  for (RangeHighlighter highlighter : myHighlighters) {
    if (!highlighter.isValid()) continue;
    boolean needsAdditionalHighlighting = false;
    TextRange cursor = mySearchResults.getCursor();
    if (cursor == null || highlighter.getStartOffset() != cursor.getStartOffset() || highlighter.getEndOffset() != cursor.getEndOffset()) {
      for (int i = 0; i < starts.length; ++i) {
        TextRange selectionRange = new TextRange(starts[i], ends[i]);
        needsAdditionalHighlighting = selectionRange.intersects(highlighter.getStartOffset(), highlighter.getEndOffset()) &&
                                      selectionRange.getEndOffset() != highlighter.getStartOffset() &&
                                      highlighter.getEndOffset() != selectionRange.getStartOffset();
        if (needsAdditionalHighlighting) break;
      }
    }

    RangeHighlighter inSelectionHighlighter = highlighter.getUserData(IN_SELECTION_KEY);
    if (inSelectionHighlighter != null) {
      if (!needsAdditionalHighlighting) {
        removeHighlighter(inSelectionHighlighter);
      }
    }
    else if (needsAdditionalHighlighting) {
      RangeHighlighter additionalHighlighter = addHighlighter(highlighter.getStartOffset(), highlighter.getEndOffset(), new TextAttributes(null, null, Color.WHITE, EffectType.ROUNDED_BOX, Font.PLAIN));
      highlighter.putUserData(IN_SELECTION_KEY, additionalHighlighter);
    }
  }
}
 
Example 5
Source File: InitialInfoBuilder.java    From consulo with Apache License 2.0 5 votes vote down vote up
private boolean isInsideExtendedAffectedRange(TextRange range) {
  if (myExtendedAffectedRanges == null) return false;

  for (TextRange affectedRange : myExtendedAffectedRanges) {
    if (affectedRange.intersects(range)) return true;
  }

  return false;
}
 
Example 6
Source File: GenericPatchApplier.java    From consulo with Apache License 2.0 4 votes vote down vote up
private boolean isSeized(final int lineNumber) {
  final TextRange art = new TextRange(lineNumber, lineNumber);
  final TextRange floor = myTransformations.floorKey(art);
  return (floor != null && floor.intersects(art));
}
 
Example 7
Source File: PathReferenceManagerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static boolean intersect(final TextRange range1, final TextRange range2) {
  return range2.intersectsStrict(range1) || range2.intersects(range1) && (range1.isEmpty() || range2.isEmpty());
}