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)));
}
}
}
}
}
}
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);
}
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);
}
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));
}
}
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;
}
Aggregations