Search in sources :

Example 1 with ManualRangeMarker

use of com.intellij.openapi.editor.impl.ManualRangeMarker 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 ManualRangeMarker

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

the class MarkerCache method createMarkers.

@NotNull
private static ManualRangeMarker[] createMarkers(List<SelfElementInfo> infos) {
    ManualRangeMarker[] markers = new ManualRangeMarker[infos.size()];
    int i = 0;
    while (i < markers.length) {
        SelfElementInfo info = infos.get(i);
        boolean greedy = info.isGreedy();
        int start = info.getPsiStartOffset();
        int end = info.getPsiEndOffset();
        markers[i] = new ManualRangeMarker(start, end, greedy, greedy, !greedy, null);
        i++;
        while (i < markers.length && rangeEquals(infos.get(i), start, end, greedy)) {
            markers[i] = markers[i - 1];
            i++;
        }
    }
    return markers;
}
Also used : ManualRangeMarker(com.intellij.openapi.editor.impl.ManualRangeMarker) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with ManualRangeMarker

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

the class MarkerCache method getUpdatedRange.

@Nullable
TextRange getUpdatedRange(@NotNull SelfElementInfo info, @NotNull FrozenDocument frozen, @NotNull List<DocumentEvent> events) {
    UpdatedRanges struct = getUpdatedMarkers(frozen, events);
    int i = Collections.binarySearch(struct.mySortedInfos, info, INFO_COMPARATOR);
    ManualRangeMarker updated = i >= 0 ? struct.myMarkers[i] : null;
    return updated == null ? null : new UnfairTextRange(updated.getStartOffset(), updated.getEndOffset());
}
Also used : ManualRangeMarker(com.intellij.openapi.editor.impl.ManualRangeMarker) UnfairTextRange(com.intellij.openapi.util.UnfairTextRange) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

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