use of com.intellij.openapi.editor.ex.DocumentEx in project intellij-community by JetBrains.
the class MultiHostRegistrarImpl method getModificationCount.
// for CachedValue
@Override
public long getModificationCount() {
List<PsiLanguageInjectionHost.Shred> shredList = shreds;
if (shredList != null) {
for (PsiLanguageInjectionHost.Shred shred : shredList) {
if (!shred.isValid())
return -1;
}
}
DocumentEx hostDocument = myHostDocument;
return hostDocument == null ? -1 : hostDocument.getModificationStamp();
}
use of com.intellij.openapi.editor.ex.DocumentEx in project intellij-community by JetBrains.
the class UndoableGroup method doUndoOrRedo.
private void doUndoOrRedo(final boolean isUndo) {
final boolean wrapInBulkUpdate = myActions.size() > 50;
// perform undo action by action, setting bulk update flag if possible
// if multiple consecutive actions share a document, then set the bulk flag only once
final UnexpectedUndoException[] exception = { null };
ApplicationManager.getApplication().runWriteAction(() -> {
final Set<DocumentEx> bulkDocuments = new THashSet<>();
try {
for (final UndoableAction action : isUndo ? ContainerUtil.iterateBackward(myActions) : myActions) {
if (wrapInBulkUpdate) {
DocumentEx newDocument = getDocumentToSetBulkMode(action);
if (newDocument == null) {
for (DocumentEx document : bulkDocuments) {
document.setInBulkUpdate(false);
}
bulkDocuments.clear();
} else if (bulkDocuments.add(newDocument)) {
newDocument.setInBulkUpdate(true);
}
}
if (isUndo) {
action.undo();
} else {
action.redo();
}
}
} catch (UnexpectedUndoException e) {
exception[0] = e;
} finally {
for (DocumentEx bulkDocument : bulkDocuments) {
bulkDocument.setInBulkUpdate(false);
}
}
});
if (exception[0] != null)
reportUndoProblem(exception[0], isUndo);
commitAllDocuments();
}
use of com.intellij.openapi.editor.ex.DocumentEx in project intellij-community by JetBrains.
the class MergeList method finishBulkUpdate.
public void finishBulkUpdate() {
Document document1 = myBaseToLeftChangeList.getDocument(BRANCH_SIDE);
Document document2 = myBaseToRightChangeList.getDocument(BRANCH_SIDE);
Document document3 = myBaseToLeftChangeList.getDocument(BASE_SIDE);
assert document3 == myBaseToRightChangeList.getDocument(BASE_SIDE);
((DocumentEx) document1).setInBulkUpdate(false);
((DocumentEx) document2).setInBulkUpdate(false);
((DocumentEx) document3).setInBulkUpdate(false);
}
use of com.intellij.openapi.editor.ex.DocumentEx in project intellij-community by JetBrains.
the class MergeList method startBulkUpdate.
public void startBulkUpdate() {
Document document1 = myBaseToLeftChangeList.getDocument(BRANCH_SIDE);
Document document2 = myBaseToRightChangeList.getDocument(BRANCH_SIDE);
Document document3 = myBaseToLeftChangeList.getDocument(BASE_SIDE);
assert document3 == myBaseToRightChangeList.getDocument(BASE_SIDE);
((DocumentEx) document1).setInBulkUpdate(true);
((DocumentEx) document2).setInBulkUpdate(true);
((DocumentEx) document3).setInBulkUpdate(true);
}
use of com.intellij.openapi.editor.ex.DocumentEx in project intellij-community by JetBrains.
the class FileDocumentManagerImplTest method testReplaceDocumentTextWithTheSameText.
public void testReplaceDocumentTextWithTheSameText() throws Exception {
final VirtualFile file = createFile();
final DocumentEx document = (DocumentEx) myDocumentManager.getDocument(file);
assertNotNull(file.toString(), document);
WriteCommandAction.runWriteCommandAction(myProject, () -> {
final String newText = "test text";
document.replaceString(0, document.getTextLength(), newText);
assertTrue(myDocumentManager.isDocumentUnsaved(document));
myDocumentManager.saveDocument(document);
getProject().getMessageBus().connect(getTestRootDisposable()).subscribe(AppTopics.FILE_DOCUMENT_SYNC, new FileDocumentManagerAdapter() {
@Override
public void beforeDocumentSaving(@NotNull Document documentToSave) {
assertNotSame(document, documentToSave);
}
});
final long modificationStamp = document.getModificationStamp();
document.replaceString(0, document.getTextLength(), newText);
if (myDocumentManager.isDocumentUnsaved(document)) {
assertTrue(document.getModificationStamp() > modificationStamp);
} else {
assertEquals(modificationStamp, document.getModificationStamp());
}
});
}
Aggregations