Search in sources :

Example 1 with DocumentEventImpl

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

the class EduDocumentListener method documentChanged.

@Override
public void documentChanged(DocumentEvent e) {
    if (!myTaskFile.isTrackChanges()) {
        return;
    }
    if (myAnswerPlaceholders.isEmpty())
        return;
    if (e instanceof DocumentEventImpl) {
        DocumentEventImpl event = (DocumentEventImpl) e;
        Document document = e.getDocument();
        int offset = e.getOffset();
        int change = event.getNewLength() - event.getOldLength();
        for (AnswerPlaceholderWrapper answerPlaceholderWrapper : myAnswerPlaceholders) {
            int twStart = answerPlaceholderWrapper.getTwStart();
            if (twStart > offset) {
                twStart += change;
            }
            int twEnd = answerPlaceholderWrapper.getTwEnd();
            if (twEnd >= offset) {
                twEnd += change;
            }
            AnswerPlaceholder answerPlaceholder = answerPlaceholderWrapper.getAnswerPlaceholder();
            int length = twEnd - twStart;
            answerPlaceholder.setOffset(twStart);
            if (myTrackLength) {
                if (answerPlaceholder.getUseLength()) {
                    answerPlaceholder.setLength(length);
                } else {
                    if (answerPlaceholder.isActive() && myTaskFile.isTrackLengths()) {
                        answerPlaceholder.setPossibleAnswer(document.getText(TextRange.create(twStart, twStart + length)));
                    }
                }
            }
        }
    }
}
Also used : DocumentEventImpl(com.intellij.openapi.editor.impl.event.DocumentEventImpl) AnswerPlaceholder(com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder) Document(com.intellij.openapi.editor.Document)

Example 2 with DocumentEventImpl

use of com.intellij.openapi.editor.impl.event.DocumentEventImpl 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 3 with DocumentEventImpl

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

the class PsiDocumentManagerImplTest method changeDocument.

private static void changeDocument(Document document, PsiDocumentManagerImpl manager) {
    DocumentEventImpl event = new DocumentEventImpl(document, 0, "", "", document.getModificationStamp(), false);
    manager.beforeDocumentChange(event);
    manager.documentChanged(event);
}
Also used : DocumentEventImpl(com.intellij.openapi.editor.impl.event.DocumentEventImpl)

Example 4 with DocumentEventImpl

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

the class ReferenceEditorWithBrowseButton method setText.

@Override
public void setText(@NotNull String text) {
    Document oldDocument = getEditorTextField().getDocument();
    String oldText = oldDocument.getText();
    for (DocumentListener listener : myDocumentListeners) {
        oldDocument.removeDocumentListener(listener);
    }
    Document document = myFactory.fun(text);
    getEditorTextField().setDocument(document);
    for (DocumentListener listener : myDocumentListeners) {
        document.addDocumentListener(listener);
        listener.documentChanged(new DocumentEventImpl(document, 0, oldText, text, -1, false));
    }
}
Also used : DocumentListener(com.intellij.openapi.editor.event.DocumentListener) DocumentEventImpl(com.intellij.openapi.editor.impl.event.DocumentEventImpl) Document(com.intellij.openapi.editor.Document)

Example 5 with DocumentEventImpl

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

the class PersistentRangeMarker method applyChange.

@Nullable
private static Pair<TextRange, LinesCols> applyChange(DocumentEvent event, Segment range, int intervalStart, int intervalEnd, boolean greedyLeft, boolean greedyRight, LinesCols linesCols) {
    final boolean shouldTranslateViaDiff = PersistentRangeMarkerUtil.shouldTranslateViaDiff(event, range.getStartOffset(), range.getEndOffset());
    Pair<TextRange, LinesCols> translated = null;
    if (shouldTranslateViaDiff) {
        translated = translateViaDiff((DocumentEventImpl) event, linesCols);
    }
    if (translated == null) {
        TextRange fallback = applyChange(event, intervalStart, intervalEnd, greedyLeft, greedyRight);
        if (fallback == null)
            return null;
        LinesCols lc = storeLinesAndCols(event.getDocument(), fallback.getStartOffset(), fallback.getEndOffset());
        if (lc == null)
            return null;
        translated = Pair.create(fallback, lc);
    }
    return translated;
}
Also used : DocumentEventImpl(com.intellij.openapi.editor.impl.event.DocumentEventImpl) TextRange(com.intellij.openapi.util.TextRange) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

DocumentEventImpl (com.intellij.openapi.editor.impl.event.DocumentEventImpl)8 Document (com.intellij.openapi.editor.Document)2 DocumentEvent (com.intellij.openapi.editor.event.DocumentEvent)2 RetargetRangeMarkers (com.intellij.openapi.editor.impl.event.RetargetRangeMarkers)2 TextRange (com.intellij.openapi.util.TextRange)2 Nullable (org.jetbrains.annotations.Nullable)2 DocumentListener (com.intellij.openapi.editor.event.DocumentListener)1 FrozenDocument (com.intellij.openapi.editor.impl.FrozenDocument)1 ManualRangeMarker (com.intellij.openapi.editor.impl.ManualRangeMarker)1 ImmutableCharSequence (com.intellij.util.text.ImmutableCharSequence)1 AnswerPlaceholder (com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder)1