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


Java EditorUtil.getSpaceWidth方法代码示例

本文整理汇总了Java中com.intellij.openapi.editor.ex.util.EditorUtil.getSpaceWidth方法的典型用法代码示例。如果您正苦于以下问题:Java EditorUtil.getSpaceWidth方法的具体用法?Java EditorUtil.getSpaceWidth怎么用?Java EditorUtil.getSpaceWidth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.openapi.editor.ex.util.EditorUtil的用法示例。


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

示例1: paintAfterLineEndBackgroundSegments

import com.intellij.openapi.editor.ex.util.EditorUtil; //导入方法依赖的package包/类
private void paintAfterLineEndBackgroundSegments(@NotNull Graphics g,
                                                 @NotNull IterationState iterationState,
                                                 @NotNull Point position,
                                                 @NotNull Color defaultBackground,
                                                 int lineHeight) {
  while (iterationState.hasPastLineEndBackgroundSegment()) {
    TextAttributes backgroundAttributes = iterationState.getPastLineEndBackgroundAttributes();
    int width = EditorUtil.getSpaceWidth(backgroundAttributes.getFontType(), this) * iterationState.getPastLineEndBackgroundSegmentWidth();
    Color color = getBackgroundColor(backgroundAttributes);
    if (color != null && !color.equals(defaultBackground)) {
      g.setColor(color);
      g.fillRect(position.x, position.y, width, lineHeight);
    }
    position.x += width;
    iterationState.advanceToNextPastLineEndBackgroundSegment();
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:bigFile.java

示例2: getPreferredSize

import com.intellij.openapi.editor.ex.util.EditorUtil; //导入方法依赖的package包/类
public Dimension getPreferredSize() {
  if (myUseNewRendering) return isReleased ? new Dimension() : myView.getPreferredSize();
  if (ourIsUnitTestMode && getUserData(DO_DOCUMENT_UPDATE_TEST) == null) {
    return new Dimension(1, 1);
  }

  final Dimension draft = getSizeWithoutCaret();
  final int additionalSpace = shouldRespectAdditionalColumns()
                              ? mySettings.getAdditionalColumnsCount() * EditorUtil.getSpaceWidth(Font.PLAIN, this)
                              : 0;

  if (!myDocument.isInBulkUpdate()) {
    for (Caret caret : myCaretModel.getAllCarets()) {
      if (caret.isUpToDate()) {
        int caretX = visualPositionToXY(caret.getVisualPosition()).x;
        draft.width = Math.max(caretX, draft.width);
      }
    }
  }
  draft.width += additionalSpace;
  return draft;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:EditorImpl.java

示例3: paintAfterLineEndBackgroundSegments

import com.intellij.openapi.editor.ex.util.EditorUtil; //导入方法依赖的package包/类
private void paintAfterLineEndBackgroundSegments(@NotNull Graphics g,
                                                 @NotNull IterationState iterationState,
                                                 @NotNull Point position,
                                                 @NotNull Color defaultBackground,
                                                 int lineHeight) {
  while (iterationState.hasPastLineEndBackgroundSegment()) {
    TextAttributes backgroundAttributes = iterationState.getPastLineEndBackgroundAttributes();
    int width =
      EditorUtil.getSpaceWidth(backgroundAttributes.getFontType(), this) * iterationState.getPastLineEndBackgroundSegmentWidth();
    Color color = getBackgroundColor(backgroundAttributes);
    if (color != null && !color.equals(defaultBackground)) {
      g.setColor(color);
      g.fillRect(position.x, position.y, width, lineHeight);
    }
    position.x += width;
    iterationState.advanceToNextPastLineEndBackgroundSegment();
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:bigFile.java

示例4: getPreferredSize

import com.intellij.openapi.editor.ex.util.EditorUtil; //导入方法依赖的package包/类
public Dimension getPreferredSize() {
  if (myUseNewRendering) return myView.getPreferredSize();
  if (ourIsUnitTestMode && getUserData(DO_DOCUMENT_UPDATE_TEST) == null) {
    return new Dimension(1, 1);
  }

  final Dimension draft = getSizeWithoutCaret();
  final int additionalSpace = shouldRespectAdditionalColumns()
                              ? mySettings.getAdditionalColumnsCount() * EditorUtil.getSpaceWidth(Font.PLAIN, this)
                              : 0;

  if (!myDocument.isInBulkUpdate()) {
    for (Caret caret : myCaretModel.getAllCarets()) {
      if (caret.isUpToDate()) {
        int caretX = visualPositionToXY(caret.getVisualPosition()).x;
        draft.width = Math.max(caretX, draft.width);
      }
    }
  }
  draft.width += additionalSpace;
  return draft;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:bigFile.java

示例5: calcAnnotationExtraSize

import com.intellij.openapi.editor.ex.util.EditorUtil; //导入方法依赖的package包/类
private void calcAnnotationExtraSize() {
  myTextAnnotationExtraSize = 0;
  if (!myEditor.isInDistractionFreeMode() || isMirrored()) return;

  Window frame = SwingUtilities.getWindowAncestor(myEditor.getComponent());
  if (frame == null) return;

  EditorSettings settings = myEditor.getSettings();
  int rightMargin = settings.getRightMargin(myEditor.getProject());
  if (rightMargin <= 0) return;

  JComponent editorComponent = myEditor.getComponent();
  RelativePoint point = new RelativePoint(editorComponent, new Point(0, 0));
  Point editorLocationInWindow = point.getPoint(frame);

  int editorLocationX = (int)editorLocationInWindow.getX();
  int rightMarginX = rightMargin * EditorUtil.getSpaceWidth(Font.PLAIN, myEditor) + editorLocationX;

  int width = editorLocationX + editorComponent.getWidth();
  if (rightMarginX < width && editorLocationX < width - rightMarginX) {
    int centeredSize = (width - rightMarginX - editorLocationX) / 2 - (getLineMarkerAreaWidth() + getLineNumberAreaWidth());
    myTextAnnotationExtraSize = Math.max(0, centeredSize - myTextAnnotationGuttersSize);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:EditorGutterComponentImpl.java

示例6: initTabPainter

import com.intellij.openapi.editor.ex.util.EditorUtil; //导入方法依赖的package包/类
private void initTabPainter() {
  myTabPainter = new ArrowPainter(
    ColorProvider.byColorsScheme(myScheme, EditorColors.WHITESPACES_COLOR),
    new Computable.PredefinedValueComputable<Integer>(EditorUtil.getSpaceWidth(Font.PLAIN, this)),
    new Computable<Integer>() {
      @Override
      public Integer compute() {
        return getCharHeight();
      }
    }
  );
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:13,代码来源:bigFile.java

示例7: paintRightMargin

import com.intellij.openapi.editor.ex.util.EditorUtil; //导入方法依赖的package包/类
private void paintRightMargin(@NotNull Graphics g, @NotNull Rectangle clip) {
  Color rightMargin = myScheme.getColor(EditorColors.RIGHT_MARGIN_COLOR);
  if (!mySettings.isRightMarginShown() || rightMargin == null) {
    return;
  }
  int x = mySettings.getRightMargin(myProject) * EditorUtil.getSpaceWidth(Font.PLAIN, this);
  if (x >= clip.x && x < clip.x + clip.width) {
    g.setColor(rightMargin);
    UIUtil.drawLine(g, x, clip.y, x, clip.y + clip.height);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:12,代码来源:bigFile.java

示例8: paintSelectionOnSecondSoftWrapLineIfNecessary

import com.intellij.openapi.editor.ex.util.EditorUtil; //导入方法依赖的package包/类
/**
 * End user is allowed to perform selection by visual coordinates (e.g. by dragging mouse with left button hold). There is a possible
 * case that such a move intersects with soft wrap introduced virtual space. We want to draw corresponding selection background
 * there then.
 * <p/>
 * This method encapsulates functionality of drawing selection background on the second soft wrap line (e.g. on a visual line after
 * the one where it is applied).
 *
 * @param g                 graphics to draw on
 * @param position          current position (assumed to be position of soft wrap appliance)
 * @param clip              target drawing area boundaries
 * @param defaultBackground default background
 * @param fontType          current font type
 * @param softWrap          target soft wrap which second line virtual space may contain selection
 */
private void paintSelectionOnSecondSoftWrapLineIfNecessary(@NotNull Graphics g,
                                                           @NotNull Point position,
                                                           @NotNull Rectangle clip,
                                                           @NotNull Color defaultBackground,
                                                           @JdkConstants.FontStyle int fontType,
                                                           @NotNull SoftWrap softWrap) {
  // There is a possible case that the user performed selection at soft wrap virtual space. We need to paint corresponding background
  // there then.
  VisualPosition selectionStartPosition = getSelectionStartPositionForPaint();
  VisualPosition selectionEndPosition = getSelectionEndPositionForPaint();
  if (selectionStartPosition.equals(selectionEndPosition)) {
    return;
  }

  int currentVisualLine = position.y / getLineHeight();

  // Check if the second soft wrap line is within the visual selection.
  if (currentVisualLine < selectionStartPosition.line || currentVisualLine > selectionEndPosition.line
      || currentVisualLine == selectionStartPosition.line && selectionStartPosition.column >= softWrap.getIndentInColumns()) {
    return;
  }

  // Adjust 'x' if selection starts at soft wrap virtual space.
  if (selectionStartPosition.line == currentVisualLine && selectionStartPosition.column > 0) {
    position.x += selectionStartPosition.column * EditorUtil.getSpaceWidth(fontType, this);
  }

  // Calculate selection width.
  final int width;
  if (selectionEndPosition.line > currentVisualLine || selectionEndPosition.column >= softWrap.getIndentInColumns()) {
    width = softWrap.getIndentInPixels() - position.x;
  }
  else {
    width = selectionEndPosition.column * EditorUtil.getSpaceWidth(fontType, this) - position.x;
  }

  drawBackground(g, getColorsScheme().getColor(EditorColors.SELECTION_BACKGROUND_COLOR), width, position, defaultBackground, clip);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:54,代码来源:EditorImpl.java

示例9: mouseReleased

import com.intellij.openapi.editor.ex.util.EditorUtil; //导入方法依赖的package包/类
@Override
public void mouseReleased(@NotNull MouseEvent e) {
  myMousePressArea = null;
  runMouseReleasedCommand(e);
  if (!e.isConsumed() && myMousePressedEvent != null && !myMousePressedEvent.isConsumed() &&
      Math.abs(e.getX() - myMousePressedEvent.getX()) < EditorUtil.getSpaceWidth(Font.PLAIN, EditorImpl.this) &&
      Math.abs(e.getY() - myMousePressedEvent.getY()) < getLineHeight()) {
    runMouseClickedCommand(e);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:11,代码来源:EditorImpl.java

示例10: getScrollableUnitIncrement

import com.intellij.openapi.editor.ex.util.EditorUtil; //导入方法依赖的package包/类
@Override
public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) {
  if (orientation == SwingConstants.VERTICAL) {
    return myEditor.getLineHeight();
  }
  // if orientation == SwingConstants.HORIZONTAL
  return EditorUtil.getSpaceWidth(Font.PLAIN, myEditor);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:9,代码来源:EditorComponentImpl.java

示例11: beforeUpdate

import com.intellij.openapi.editor.ex.util.EditorUtil; //导入方法依赖的package包/类
public void beforeUpdate(@NotNull DocumentEvent e) {
  if (isZeroLatencyTypingEnabled() && myImmediateEditingInProgress && canPaintImmediately(e)) {
    int offset = e.getOffset();
    int length = e.getOldLength();

    myOldArea = lineRectangleBetween(offset, offset + length);

    myOldTailArea = lineRectangleBetween(offset + length, getDocument().getLineEndOffset(getDocument().getLineNumber(offset)));
    if (myOldTailArea.isEmpty()) {
      myOldTailArea.width += EditorUtil.getSpaceWidth(Font.PLAIN, myEditor); // include possible caret
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:14,代码来源:ImmediatePainter.java

示例12: blinkHighlighters

import com.intellij.openapi.editor.ex.util.EditorUtil; //导入方法依赖的package包/类
private void blinkHighlighters() {
  MarkupModel markupModel = myEditor.getMarkupModel();
  if (myShowsPreviewHighlighters) {
    Rectangle visibleArea = myEditor.getScrollingModel().getVisibleArea();
    VisualPosition visualStart = myEditor.xyToVisualPosition(visibleArea.getLocation());
    VisualPosition visualEnd = myEditor.xyToVisualPosition(new Point(visibleArea.x + visibleArea.width, visibleArea.y + visibleArea.height));

    // There is a possible case that viewport is located at its most bottom position and last document symbol
    // is located at the start of the line, hence, resulting visual end column has a small value and doesn't actually
    // indicates target visible rectangle. Hence, we need to correct that if necessary.
    int endColumnCandidate = visibleArea.width / EditorUtil.getSpaceWidth(Font.PLAIN, myEditor) + visualStart.column;
    if (endColumnCandidate > visualEnd.column) {
      visualEnd = new VisualPosition(visualEnd.line, endColumnCandidate);
    }
    int offsetToScroll = -1;
    CharSequence text = myEditor.getDocument().getCharsSequence();
    TextAttributes backgroundAttributes = myEditor.getColorsScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
    TextAttributes borderAttributes = new TextAttributes(
      null, null, backgroundAttributes.getBackgroundColor(), EffectType.BOXED, Font.PLAIN
    );
    boolean scrollToChange = true;
    for (TextRange range : myPreviewRangesToHighlight) {
      if (scrollToChange) {
        boolean rangeVisible = isWithinBounds(myEditor.offsetToVisualPosition(range.getStartOffset()), visualStart, visualEnd)
                               || isWithinBounds(myEditor.offsetToVisualPosition(range.getEndOffset()), visualStart, visualEnd);
        scrollToChange = !rangeVisible;
        if (offsetToScroll < 0) {
          if (offsetToScroll < 0) {
            if (text.charAt(range.getStartOffset()) != '\n') {
              offsetToScroll = range.getStartOffset();
            }
            else if (range.getEndOffset() > 0 && text.charAt(range.getEndOffset() - 1) != '\n') {
              offsetToScroll = range.getEndOffset() - 1;
            }
          }
        }
      }

      TextAttributes attributesToUse = range.getLength() > 0 ? backgroundAttributes : borderAttributes;
      markupModel.addRangeHighlighter(
        range.getStartOffset(), range.getEndOffset(), HighlighterLayer.SELECTION, attributesToUse, HighlighterTargetArea.EXACT_RANGE
      );
    }

    if (scrollToChange) {
      if (offsetToScroll < 0 && !myPreviewRangesToHighlight.isEmpty()) {
        offsetToScroll = myPreviewRangesToHighlight.get(0).getStartOffset();
      }
      if (offsetToScroll >= 0 && offsetToScroll < text.length() - 1 && text.charAt(offsetToScroll) != '\n') {
        // There is a possible case that target offset is located too close to the right edge. However, our point is to show
        // highlighted region at target offset, hence, we need to scroll to the visual symbol end. Hence, we're trying to ensure
        // that by scrolling to the symbol's end over than its start.
        offsetToScroll++;
      }
      if (offsetToScroll >= 0 && offsetToScroll < myEditor.getDocument().getTextLength()) {
        myEditor.getScrollingModel().scrollTo(
          myEditor.offsetToLogicalPosition(offsetToScroll), ScrollType.RELATIVE
        );
      }
    }
  }
  else {
    markupModel.removeAllHighlighters();
  }
  myShowsPreviewHighlighters = !myShowsPreviewHighlighters;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:67,代码来源:CodeStyleAbstractPanel.java

示例13: paintSelectionOnFirstSoftWrapLineIfNecessary

import com.intellij.openapi.editor.ex.util.EditorUtil; //导入方法依赖的package包/类
/**
 * End user is allowed to perform selection by visual coordinates (e.g. by dragging mouse with left button hold). There is a possible
 * case that such a move intersects with soft wrap introduced virtual space. We want to draw corresponding selection background
 * there then.
 * <p/>
 * This method encapsulates functionality of drawing selection background on the first soft wrap line (e.g. on a visual line where
 * it is applied).
 *
 * @param g                 graphics to draw on
 * @param position          current position (assumed to be position of soft wrap appliance)
 * @param clip              target drawing area boundaries
 * @param defaultBackground default background
 * @param fontType          current font type
 */
private void paintSelectionOnFirstSoftWrapLineIfNecessary(@NotNull Graphics g,
                                                          @NotNull Point position,
                                                          @NotNull Rectangle clip,
                                                          @NotNull Color defaultBackground,
                                                          @JdkConstants.FontStyle int fontType) {
  // There is a possible case that the user performed selection at soft wrap virtual space. We need to paint corresponding background
  // there then.
  VisualPosition selectionStartPosition = getSelectionStartPositionForPaint();
  VisualPosition selectionEndPosition = getSelectionEndPositionForPaint();
  if (selectionStartPosition.equals(selectionEndPosition)) {
    return;
  }

  int currentVisualLine = position.y / getLineHeight();
  int lastColumn = EditorUtil.getLastVisualLineColumnNumber(this, currentVisualLine);

  // Check if the first soft wrap line is within the visual selection.
  if (currentVisualLine < selectionStartPosition.line || currentVisualLine > selectionEndPosition.line
      || currentVisualLine == selectionEndPosition.line && selectionEndPosition.column <= lastColumn) {
    return;
  }

  // Adjust 'x' if selection starts at soft wrap virtual space.
  final int columnsToSkip = selectionStartPosition.column - lastColumn;
  if (columnsToSkip > 0) {
    position.x += getSoftWrapModel().getMinDrawingWidthInPixels(SoftWrapDrawingType.BEFORE_SOFT_WRAP_LINE_FEED);
    position.x += (columnsToSkip - 1) * EditorUtil.getSpaceWidth(Font.PLAIN, this);
  }

  // Calculate selection width.
  final int width;
  if (selectionEndPosition.line > currentVisualLine) {
    width = clip.x + clip.width - position.x;
  }
  else if (selectionStartPosition.line < currentVisualLine || selectionStartPosition.column <= lastColumn) {
    width = getSoftWrapModel().getMinDrawingWidthInPixels(SoftWrapDrawingType.BEFORE_SOFT_WRAP_LINE_FEED)
            + (selectionEndPosition.column - lastColumn - 1) * EditorUtil.getSpaceWidth(fontType, this);
  }
  else {
    width = (selectionEndPosition.column - selectionStartPosition.column) * EditorUtil.getSpaceWidth(fontType, this);
  }

  drawBackground(g, getColorsScheme().getColor(EditorColors.SELECTION_BACKGROUND_COLOR), width, position, defaultBackground, clip);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:59,代码来源:bigFile.java

示例14: doRecalculateSoftWraps

import com.intellij.openapi.editor.ex.util.EditorUtil; //导入方法依赖的package包/类
private void doRecalculateSoftWraps(IncrementalCacheUpdateEvent event) {
  myEventBeingProcessed = event;
  notifyListenersOnCacheUpdateStart(event);
  // Preparation.
  myContext.reset();
  myOffset2fontType.clear();
  myOffset2widthInPixels.clear();

  // Define start of the visual line that holds target range start.
  final int start = event.getStartOffset(); 
  final LogicalPosition logical = event.getStartLogicalPosition();

  Document document = myEditor.getDocument();
  myContext.text = document.getCharsSequence();
  myContext.tokenStartOffset = start;
  IterationState iterationState = new IterationState(myEditor, start, document.getTextLength(), false);
  TextAttributes attributes = iterationState.getMergedAttributes();
  myContext.fontType = attributes.getFontType();
  myContext.rangeEndOffset = event.getMandatoryEndOffset();

  EditorPosition position = myEditor.myUseNewRendering ? new EditorPosition(logical, event.getStartVisualPosition(), start, myEditor) : 
                            new EditorPosition(logical, start, myEditor);
  position.x = start == 0 ? myEditor.getPrefixTextWidthInPixels() : 0;
  int spaceWidth = EditorUtil.getSpaceWidth(myContext.fontType, myEditor);
  int plainSpaceWidth = EditorUtil.getSpaceWidth(Font.PLAIN, myEditor);

  myContext.logicalLineData.update(logical.line, spaceWidth, plainSpaceWidth);

  myContext.currentPosition = position;
  myContext.lineStartPosition = position.clone();
  myContext.fontType2spaceWidth.put(myContext.fontType, spaceWidth);
  myContext.softWrapStartOffset = position.offset;

  myContext.reservedWidthInPixels = myPainter.getMinDrawingWidth(SoftWrapDrawingType.BEFORE_SOFT_WRAP_LINE_FEED);
  
  SoftWrap softWrapAtStartPosition = myStorage.getSoftWrap(start);
  if (softWrapAtStartPosition != null) {
    myContext.currentPosition.x = softWrapAtStartPosition.getIndentInPixels();
    myContext.lineStartPosition.visualColumn = 0;
    myContext.lineStartPosition.softWrapColumnDiff -= softWrapAtStartPosition.getIndentInColumns();
    myContext.softWrapStartOffset++;
    
    notifyListenersOnVisualLineStart(myContext.lineStartPosition);
  }

  // Perform soft wraps calculation.
  while (!iterationState.atEnd()) {
    FoldRegion currentFold = iterationState.getCurrentFold();
    if (currentFold == null) {
      myContext.tokenEndOffset = iterationState.getEndOffset();
      if (processNonFoldToken()) {
        break;
      }
    }
    else {
      if (processCollapsedFoldRegion(currentFold)) {
        break;
      }

      // 'myOffset2widthInPixels' contains information necessary to processing soft wraps that lay before the current offset.
      // We do know that soft wraps are not allowed to go backward after processed collapsed fold region, hence, we drop
      // information about processed symbols width.
      myOffset2widthInPixels.clear();
    }

    iterationState.advance();
    attributes = iterationState.getMergedAttributes();
    myContext.fontType = attributes.getFontType();
    myContext.tokenStartOffset = iterationState.getStartOffset();
    myOffset2fontType.fill(myContext.tokenStartOffset, iterationState.getEndOffset(), myContext.fontType);
  }
  if (myContext.delayedSoftWrap != null) {
    myStorage.remove(myContext.delayedSoftWrap);
  }
  notifyListenersOnVisualLineEnd();
  event.setActualEndOffset(myContext.currentPosition.offset);
  validateFinalPosition(event);
  notifyListenersOnCacheUpdateEnd(event);
  myEventBeingProcessed = null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:81,代码来源:SoftWrapApplianceManager.java

示例15: doWrapLongLinesIfNecessary

import com.intellij.openapi.editor.ex.util.EditorUtil; //导入方法依赖的package包/类
public void doWrapLongLinesIfNecessary(@NotNull final Editor editor, @NotNull final Project project, @NotNull Document document,
                                       int startOffset, int endOffset) {
  // Normalization.
  int startOffsetToUse = Math.min(document.getTextLength(), Math.max(0, startOffset));
  int endOffsetToUse = Math.min(document.getTextLength(), Math.max(0, endOffset));

  LineWrapPositionStrategy strategy = LanguageLineWrapPositionStrategy.INSTANCE.forEditor(editor);
  CharSequence text = document.getCharsSequence();
  int startLine = document.getLineNumber(startOffsetToUse);
  int endLine = document.getLineNumber(Math.max(0, endOffsetToUse - 1));
  int maxLine = Math.min(document.getLineCount(), endLine + 1);
  int tabSize = EditorUtil.getTabSize(editor);
  if (tabSize <= 0) {
    tabSize = 1;
  }
  int spaceSize = EditorUtil.getSpaceWidth(Font.PLAIN, editor);
  int[] shifts = new int[2];
  // shifts[0] - lines shift.
  // shift[1] - offset shift.

  for (int line = startLine; line < maxLine; line++) {
    int startLineOffset = document.getLineStartOffset(line);
    int endLineOffset = document.getLineEndOffset(line);
    final int preferredWrapPosition
      = calculatePreferredWrapPosition(editor, text, tabSize, spaceSize, startLineOffset, endLineOffset, endOffsetToUse);

    if (preferredWrapPosition < 0 || preferredWrapPosition >= endLineOffset) {
      continue;
    }
    if (preferredWrapPosition >= endOffsetToUse) {
      return;
    }

    // We know that current line exceeds right margin if control flow reaches this place, so, wrap it.
    int wrapOffset = strategy.calculateWrapPosition(
      document, editor.getProject(), Math.max(startLineOffset, startOffsetToUse), Math.min(endLineOffset, endOffsetToUse),
      preferredWrapPosition, false, false
    );
    if (wrapOffset < 0 // No appropriate wrap position is found.
        // No point in splitting line when its left part contains only white spaces, example:
        //    line start -> |                   | <- right margin
        //                  |   aaaaaaaaaaaaaaaa|aaaaaaaaaaaaaaaaaaaa() <- don't want to wrap this line even if it exceeds right margin
        || CharArrayUtil.shiftBackward(text, startLineOffset, wrapOffset - 1, " \t") < startLineOffset) {
      continue;
    }

    // Move caret to the target position and emulate pressing <enter>.
    editor.getCaretModel().moveToOffset(wrapOffset);
    emulateEnter(editor, project, shifts);

    //If number of inserted symbols on new line after wrapping more or equal then symbols left on previous line
    //there was no point to wrapping it, so reverting to before wrapping version
    if (shifts[1] - 1 >= wrapOffset - startLineOffset) {
      document.deleteString(wrapOffset, wrapOffset + shifts[1]);
    }
    else {
      // We know that number of lines is just increased, hence, update the data accordingly.
      maxLine += shifts[0];
      endOffsetToUse += shifts[1];
    }

  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:64,代码来源:CodeFormatterFacade.java


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