Search in sources :

Example 6 with DocumentEventImpl

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

the class PersistentRangeHighlighterImpl method changedUpdateImpl.

@Override
protected void changedUpdateImpl(@NotNull DocumentEvent e) {
    // todo Denis Zhdanov
    DocumentEventImpl event = (DocumentEventImpl) e;
    final boolean shouldTranslateViaDiff = isValid() && PersistentRangeMarkerUtil.shouldTranslateViaDiff(event, getStartOffset(), getEndOffset());
    boolean wasTranslatedViaDiff = shouldTranslateViaDiff;
    if (shouldTranslateViaDiff) {
        wasTranslatedViaDiff = translatedViaDiff(e, event);
    }
    if (!wasTranslatedViaDiff) {
        super.changedUpdateImpl(e);
        if (isValid()) {
            myLine = getDocument().getLineNumber(getStartOffset());
            int endLine = getDocument().getLineNumber(getEndOffset());
            if (endLine != myLine) {
                setIntervalEnd(getDocument().getLineEndOffset(myLine));
            }
        }
    }
    if (isValid() && getTargetArea() == HighlighterTargetArea.LINES_IN_RANGE) {
        setIntervalStart(DocumentUtil.getFirstNonSpaceCharOffset(getDocument(), myLine));
        setIntervalEnd(getDocument().getLineEndOffset(myLine));
    }
}
Also used : DocumentEventImpl(com.intellij.openapi.editor.impl.event.DocumentEventImpl)

Example 7 with DocumentEventImpl

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

the class DocumentImpl method updateText.

private void updateText(@NotNull ImmutableCharSequence newText, int offset, @NotNull CharSequence oldString, @NotNull CharSequence newString, boolean wholeTextReplaced, long newModificationStamp, int initialStartOffset, int initialOldLength) {
    assertNotNestedModification();
    myChangeInProgress = true;
    try {
        DocumentEvent event = new DocumentEventImpl(this, offset, oldString, newString, myModificationStamp, wholeTextReplaced, initialStartOffset, initialOldLength);
        beforeChangedUpdate(event);
        myTextString = null;
        ImmutableCharSequence prevText = myText;
        myText = newText;
        // increment sequence before firing events so that modification sequence on commit will match this sequence now
        sequence.incrementAndGet();
        changedUpdate(event, newModificationStamp, prevText);
    } finally {
        myChangeInProgress = false;
    }
}
Also used : DocumentEventImpl(com.intellij.openapi.editor.impl.event.DocumentEventImpl) ImmutableCharSequence(com.intellij.util.text.ImmutableCharSequence) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent)

Example 8 with DocumentEventImpl

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