Search in sources :

Example 1 with IterationState

use of com.intellij.openapi.editor.impl.view.IterationState in project intellij-community by JetBrains.

the class EditorGutterComponentImpl method paintEditorBackgrounds.

private void paintEditorBackgrounds(Graphics g, int firstVisibleOffset, int lastVisibleOffset) {
    myTextFgColors.clear();
    Color defaultBackgroundColor = myEditor.getBackgroundColor();
    Color defaultForegroundColor = myEditor.getColorsScheme().getDefaultForeground();
    int startX = myEditor.isInDistractionFreeMode() ? 0 : getWhitespaceSeparatorOffset();
    IterationState state = new IterationState(myEditor, firstVisibleOffset, lastVisibleOffset, null, true, false, true, false);
    while (!state.atEnd()) {
        drawEditorBackgroundForRange(g, state.getStartOffset(), state.getEndOffset(), state.getMergedAttributes(), defaultBackgroundColor, defaultForegroundColor, startX);
        state.advance();
    }
}
Also used : JBColor(com.intellij.ui.JBColor) IterationState(com.intellij.openapi.editor.impl.view.IterationState) RelativePoint(com.intellij.ui.awt.RelativePoint) HintHint(com.intellij.ui.HintHint)

Example 2 with IterationState

use of com.intellij.openapi.editor.impl.view.IterationState in project intellij-community by JetBrains.

the class IterationStateTest method testBoldDefaultFont.

public void testBoldDefaultFont() {
    init("abc");
    myFixture.getEditor().getColorsScheme().setAttributes(HighlighterColors.TEXT, new TextAttributes(Color.black, Color.white, null, null, Font.BOLD));
    IterationState it = new IterationState((EditorEx) myFixture.getEditor(), 0, 3, null, false, false, true, false);
    assertFalse(it.atEnd());
    assertEquals(0, it.getStartOffset());
    assertEquals(3, it.getEndOffset());
    TextAttributes attributes = it.getMergedAttributes();
    assertEquals(Font.BOLD, attributes.getFontType());
}
Also used : TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) IterationState(com.intellij.openapi.editor.impl.view.IterationState)

Example 3 with IterationState

use of com.intellij.openapi.editor.impl.view.IterationState in project intellij-community by JetBrains.

the class IterationStateTest method verifySplitting.

private void verifySplitting(boolean checkForegroundColor, @NotNull Segment... expectedSegments) {
    EditorEx editor = (EditorEx) myFixture.getEditor();
    IterationState.CaretData caretData = IterationState.createCaretData(editor);
    IterationState iterationState = new IterationState(editor, 0, editor.getDocument().getTextLength(), caretData, false, false, true, false);
    List<Segment> actualSegments = new ArrayList<>();
    do {
        Segment segment = new Segment(iterationState.getStartOffset(), iterationState.getEndOffset(), checkForegroundColor ? iterationState.getMergedAttributes().getForegroundColor() : iterationState.getMergedAttributes().getBackgroundColor());
        actualSegments.add(segment);
        iterationState.advance();
    } while (!iterationState.atEnd());
    Assert.assertArrayEquals(expectedSegments, actualSegments.toArray());
}
Also used : EditorEx(com.intellij.openapi.editor.ex.EditorEx) ArrayList(java.util.ArrayList) IterationState(com.intellij.openapi.editor.impl.view.IterationState)

Example 4 with IterationState

use of com.intellij.openapi.editor.impl.view.IterationState in project intellij-community by JetBrains.

the class SoftWrapApplianceManager method doRecalculateSoftWraps.

private void doRecalculateSoftWraps(IncrementalCacheUpdateEvent event) {
    myEventBeingProcessed = event;
    notifyListenersOnCacheUpdateStart(event);
    // Preparation.
    myContext.reset();
    myOffset2fontType.clear();
    myOffset2widthInPixels.clear();
    EditorTextRepresentationHelper editorTextRepresentationHelper = SoftWrapModelImpl.getEditorTextRepresentationHelper(myEditor);
    if (editorTextRepresentationHelper instanceof DefaultEditorTextRepresentationHelper) {
        ((DefaultEditorTextRepresentationHelper) editorTextRepresentationHelper).updateContext();
    }
    // Define start of the visual line that holds target range start.
    final int start = event.getStartOffset();
    final LogicalPosition logical = event.getStartLogicalPosition();
    int endOffsetUpperEstimate = getEndOffsetUpperEstimate(event);
    Document document = myEditor.getDocument();
    myContext.text = document.getCharsSequence();
    myContext.tokenStartOffset = start;
    IterationState iterationState = new IterationState(myEditor, start, document.getTextLength(), null, false, false, true, false);
    TextAttributes attributes = iterationState.getMergedAttributes();
    myContext.fontType = attributes.getFontType();
    myContext.rangeEndOffset = event.getMandatoryEndOffset();
    EditorPosition position = 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.softWrapStartOffset++;
    }
    myContext.inlays = myEditor.getInlayModel().getInlineElementsInRange(start, endOffsetUpperEstimate);
    // Perform soft wraps calculation.
    while (!iterationState.atEnd()) {
        FoldRegion currentFold = iterationState.getCurrentFold();
        if (currentFold == null) {
            myContext.tokenEndOffset = iterationState.getEndOffset();
            myContext.nextIsFoldRegion = iterationState.nextIsFoldRegion();
            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);
    }
    event.setActualEndOffset(myContext.currentPosition.offset);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Soft wrap recalculation done: " + event.toString() + ". " + (event.getActualEndOffset() - event.getStartOffset()) + " characters processed");
    }
    if (event.getActualEndOffset() > endOffsetUpperEstimate) {
        LOG.error("Unexpected error at soft wrap recalculation", new Attachment("softWrapModel.txt", myEditor.getSoftWrapModel().toString()));
    }
    notifyListenersOnCacheUpdateEnd(event);
    myEventBeingProcessed = null;
}
Also used : IterationState(com.intellij.openapi.editor.impl.view.IterationState) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) Attachment(com.intellij.openapi.diagnostic.Attachment)

Aggregations

IterationState (com.intellij.openapi.editor.impl.view.IterationState)4 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)2 Attachment (com.intellij.openapi.diagnostic.Attachment)1 EditorEx (com.intellij.openapi.editor.ex.EditorEx)1 HintHint (com.intellij.ui.HintHint)1 JBColor (com.intellij.ui.JBColor)1 RelativePoint (com.intellij.ui.awt.RelativePoint)1 ArrayList (java.util.ArrayList)1