Search in sources :

Example 1 with SoftWrapImpl

use of com.intellij.openapi.editor.impl.softwrap.SoftWrapImpl in project intellij-community by JetBrains.

the class SoftWrapApplianceManager method createSoftWrapIfPossible.

private boolean createSoftWrapIfPossible() {
    final int offset = myContext.currentPosition.offset;
    myContext.logicalLineData.update(offset);
    int softWrapStartOffset = myContext.softWrapStartOffset;
    int preferredOffset = Math.max(softWrapStartOffset, offset - 1);
    SoftWrapImpl softWrap = registerSoftWrap(softWrapStartOffset, preferredOffset, myContext.logicalLineData.endLineOffset, myContext.getSpaceWidth(), myContext.logicalLineData);
    FoldRegion revertedToFoldRegion = null;
    if (softWrap == null) {
        EditorPosition wrapPosition = null;
        // Try to insert soft wrap after the last collapsed fold region that is located on the current visual line.
        if (myContext.lastFoldEndPosition != null && myStorage.getSoftWrap(myContext.lastFoldEndPosition.offset) == null) {
            wrapPosition = myContext.lastFoldEndPosition;
        }
        if (wrapPosition == null && myContext.lastFoldStartPosition != null && myStorage.getSoftWrap(myContext.lastFoldStartPosition.offset) == null && myContext.lastFoldStartPosition.offset < myContext.currentPosition.offset) {
            wrapPosition = myContext.lastFoldStartPosition;
        }
        if (wrapPosition != null) {
            myContext.currentPosition = wrapPosition;
            softWrap = registerSoftWrap(wrapPosition.offset, myContext.getSpaceWidth(), myContext.logicalLineData);
            myContext.tokenStartOffset = wrapPosition.offset;
            revertedToFoldRegion = myContext.lastFold;
        } else {
            return myContext.tryToShiftToNextLine();
        }
    }
    myContext.skipToLineEnd = false;
    int actualSoftWrapOffset = softWrap.getStart();
    // We should process that accordingly.
    if (actualSoftWrapOffset > myContext.tokenEndOffset) {
        myContext.delayedSoftWrap = softWrap;
        myContext.onNonLineFeedSymbol(Character.codePointAt(myContext.text, offset));
        return false;
    } else if (actualSoftWrapOffset < offset) {
        if (revertedToFoldRegion == null) {
            while (myContext.currentPosition.offset > actualSoftWrapOffset) {
                int prevOffset = Character.offsetByCodePoints(myContext.text, myContext.currentPosition.offset, -1);
                int pixelsDiff = myOffset2widthInPixels.data[prevOffset - myOffset2widthInPixels.anchor];
                myContext.currentPosition.offset = prevOffset;
                myContext.currentPosition.x -= pixelsDiff;
            }
        }
    } else if (actualSoftWrapOffset > offset) {
        while (myContext.currentPosition.offset < actualSoftWrapOffset) {
            myContext.onNonLineFeedSymbol(Character.codePointAt(myContext.text, myContext.currentPosition.offset));
        }
    }
    processSoftWrap(softWrap);
    myContext.currentPosition.offset = actualSoftWrapOffset;
    myOffset2fontType.clear();
    myOffset2widthInPixels.clear();
    if (checkIsDoneAfterSoftWrap()) {
        return true;
    }
    if (revertedToFoldRegion != null && myContext.currentPosition.offset == revertedToFoldRegion.getStartOffset()) {
        return processCollapsedFoldRegion(revertedToFoldRegion);
    }
    return false;
}
Also used : SoftWrapImpl(com.intellij.openapi.editor.impl.softwrap.SoftWrapImpl)

Example 2 with SoftWrapImpl

use of com.intellij.openapi.editor.impl.softwrap.SoftWrapImpl in project intellij-community by JetBrains.

the class CachingSoftWrapDataMapper method advanceSoftWrapOffsets.

/**
   * Determines which soft wraps were not affected by recalculation, and shifts them to their new offsets.
   *
   * @return Change in soft wraps count after recalculation
   */
private void advanceSoftWrapOffsets(@NotNull IncrementalCacheUpdateEvent event) {
    int lengthDiff = event.getLengthDiff();
    int recalcEndOffsetTranslated = event.getActualEndOffset() - lengthDiff;
    int firstIndex = -1;
    int softWrappedLinesDiff = myStorage.getNumberOfSoftWrapsInRange(event.getStartOffset() + 1, myEditor.getDocument().getTextLength());
    boolean softWrapsChanged = softWrappedLinesDiff > 0;
    for (int i = 0; i < myAffectedByUpdateSoftWraps.size(); i++) {
        SoftWrap softWrap = myAffectedByUpdateSoftWraps.get(i);
        if (firstIndex < 0) {
            if (softWrap.getStart() > recalcEndOffsetTranslated) {
                firstIndex = i;
                if (lengthDiff == 0) {
                    break;
                }
            } else {
                softWrappedLinesDiff--;
                softWrapsChanged = true;
            }
        }
        if (firstIndex >= 0 && i >= firstIndex) {
            ((SoftWrapImpl) softWrap).advance(lengthDiff);
        }
    }
    if (firstIndex >= 0) {
        List<SoftWrapImpl> updated = myAffectedByUpdateSoftWraps.subList(firstIndex, myAffectedByUpdateSoftWraps.size());
        SoftWrapImpl lastSoftWrap = getLastSoftWrap();
        if (lastSoftWrap != null && lastSoftWrap.getStart() >= updated.get(0).getStart()) {
            LOG.error("Invalid soft wrap recalculation", new Attachment("state.txt", myEditor.getSoftWrapModel().toString()));
        }
        myStorage.addAll(updated);
    }
    myAffectedByUpdateSoftWraps.clear();
    if (softWrapsChanged) {
        myStorage.notifyListenersAboutChange();
    }
}
Also used : SoftWrapImpl(com.intellij.openapi.editor.impl.softwrap.SoftWrapImpl) Attachment(com.intellij.openapi.diagnostic.Attachment)

Example 3 with SoftWrapImpl

use of com.intellij.openapi.editor.impl.softwrap.SoftWrapImpl in project intellij-community by JetBrains.

the class SoftWrapApplianceManager method registerSoftWrap.

@NotNull
private SoftWrapImpl registerSoftWrap(int offset, int spaceSize, LogicalLineData lineData) {
    assert !DocumentUtil.isInsideSurrogatePair(myEditor.getDocument(), offset);
    int indentInColumns = 0;
    int indentInPixels = myPainter.getMinDrawingWidth(SoftWrapDrawingType.AFTER_SOFT_WRAP);
    if (myCustomIndentUsedLastTime) {
        indentInColumns = myCustomIndentValueUsedLastTime + lineData.indentInColumns;
        indentInPixels += lineData.indentInPixels + (myCustomIndentValueUsedLastTime * spaceSize);
    }
    SoftWrapImpl result = new SoftWrapImpl(new TextChangeImpl("\n" + StringUtil.repeatSymbol(' ', indentInColumns), offset, offset), indentInColumns + 1, /* for 'after soft wrap' drawing */
    indentInPixels);
    myStorage.storeOrReplace(result);
    return result;
}
Also used : SoftWrapImpl(com.intellij.openapi.editor.impl.softwrap.SoftWrapImpl) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with SoftWrapImpl

use of com.intellij.openapi.editor.impl.softwrap.SoftWrapImpl in project intellij-community by JetBrains.

the class SoftWrapApplianceManager method checkIsDoneAfterSoftWrap.

private boolean checkIsDoneAfterSoftWrap() {
    SoftWrapImpl lastSoftWrap = myDataMapper.getLastSoftWrap();
    LOG.assertTrue(lastSoftWrap != null);
    return myContext.currentPosition.offset > myContext.rangeEndOffset && myDataMapper.matchesOldSoftWrap(lastSoftWrap, myEventBeingProcessed.getLengthDiff());
}
Also used : SoftWrapImpl(com.intellij.openapi.editor.impl.softwrap.SoftWrapImpl)

Aggregations

SoftWrapImpl (com.intellij.openapi.editor.impl.softwrap.SoftWrapImpl)4 Attachment (com.intellij.openapi.diagnostic.Attachment)1 NotNull (org.jetbrains.annotations.NotNull)1