Search in sources :

Example 1 with RetargetRangeMarkers

use of com.intellij.openapi.editor.impl.event.RetargetRangeMarkers in project intellij-community by JetBrains.

the class MarkerCache method applyEvents.

private static UpdatedRanges applyEvents(@NotNull List<DocumentEvent> events, final UpdatedRanges struct) {
    FrozenDocument frozen = struct.myResultDocument;
    ManualRangeMarker[] resultMarkers = struct.myMarkers.clone();
    for (DocumentEvent event : events) {
        final FrozenDocument before = frozen;
        final DocumentEvent corrected;
        if (event instanceof RetargetRangeMarkers) {
            RetargetRangeMarkers retarget = (RetargetRangeMarkers) event;
            corrected = new RetargetRangeMarkers(frozen, retarget.getStartOffset(), retarget.getEndOffset(), retarget.getMoveDestinationOffset());
        } else {
            corrected = new DocumentEventImpl(frozen, event.getOffset(), event.getOldFragment(), event.getNewFragment(), event.getOldTimeStamp(), event.isWholeTextReplaced(), ((DocumentEventImpl) event).getInitialStartOffset(), ((DocumentEventImpl) event).getInitialOldLength());
            frozen = frozen.applyEvent(event, 0);
        }
        int i = 0;
        while (i < resultMarkers.length) {
            ManualRangeMarker currentRange = resultMarkers[i];
            int sameMarkersEnd = i + 1;
            while (sameMarkersEnd < resultMarkers.length && resultMarkers[sameMarkersEnd] == currentRange) {
                sameMarkersEnd++;
            }
            ManualRangeMarker updatedRange = currentRange == null ? null : currentRange.getUpdatedRange(corrected, before);
            while (i < sameMarkersEnd) {
                resultMarkers[i] = updatedRange;
                i++;
            }
        }
    }
    return new UpdatedRanges(struct.myEventCount + events.size(), frozen, struct.mySortedInfos, resultMarkers);
}
Also used : FrozenDocument(com.intellij.openapi.editor.impl.FrozenDocument) DocumentEventImpl(com.intellij.openapi.editor.impl.event.DocumentEventImpl) ManualRangeMarker(com.intellij.openapi.editor.impl.ManualRangeMarker) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) RetargetRangeMarkers(com.intellij.openapi.editor.impl.event.RetargetRangeMarkers)

Example 2 with RetargetRangeMarkers

use of com.intellij.openapi.editor.impl.event.RetargetRangeMarkers in project intellij-community by JetBrains.

the class ManualRangeMarker method getUpdatedRange.

@Nullable
public ManualRangeMarker getUpdatedRange(@NotNull DocumentEvent event, @NotNull FrozenDocument documentBefore) {
    if (event instanceof RetargetRangeMarkers) {
        int start = ((RetargetRangeMarkers) event).getStartOffset();
        if (myStart >= start && myEnd <= ((RetargetRangeMarkers) event).getEndOffset()) {
            int delta = ((RetargetRangeMarkers) event).getMoveDestinationOffset() - start;
            return new ManualRangeMarker(myStart + delta, myEnd + delta, myGreedyLeft, myGreedyRight, mySurviveOnExternalChange, null);
        }
    }
    if (mySurviveOnExternalChange && PersistentRangeMarkerUtil.shouldTranslateViaDiff(event, myStart, myEnd)) {
        PersistentRangeMarker.LinesCols linesCols = myLinesCols != null ? myLinesCols : PersistentRangeMarker.storeLinesAndCols(documentBefore, myStart, myEnd);
        Pair<TextRange, PersistentRangeMarker.LinesCols> pair = linesCols == null ? null : PersistentRangeMarker.translateViaDiff((DocumentEventImpl) event, linesCols);
        if (pair != null) {
            return new ManualRangeMarker(pair.first.getStartOffset(), pair.first.getEndOffset(), myGreedyLeft, myGreedyRight, true, pair.second);
        }
    }
    TextRange range = RangeMarkerImpl.applyChange(event, myStart, myEnd, myGreedyLeft, myGreedyRight);
    return range == null ? null : new ManualRangeMarker(range.getStartOffset(), range.getEndOffset(), myGreedyLeft, myGreedyRight, mySurviveOnExternalChange, null);
}
Also used : DocumentEventImpl(com.intellij.openapi.editor.impl.event.DocumentEventImpl) TextRange(com.intellij.openapi.util.TextRange) RetargetRangeMarkers(com.intellij.openapi.editor.impl.event.RetargetRangeMarkers) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

DocumentEventImpl (com.intellij.openapi.editor.impl.event.DocumentEventImpl)2 RetargetRangeMarkers (com.intellij.openapi.editor.impl.event.RetargetRangeMarkers)2 DocumentEvent (com.intellij.openapi.editor.event.DocumentEvent)1 FrozenDocument (com.intellij.openapi.editor.impl.FrozenDocument)1 ManualRangeMarker (com.intellij.openapi.editor.impl.ManualRangeMarker)1 TextRange (com.intellij.openapi.util.TextRange)1 Nullable (org.jetbrains.annotations.Nullable)1