Search in sources :

Example 46 with DocumentEx

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();
}
Also used : DocumentEx(com.intellij.openapi.editor.ex.DocumentEx)

Example 47 with DocumentEx

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();
}
Also used : DocumentEx(com.intellij.openapi.editor.ex.DocumentEx) UnexpectedUndoException(com.intellij.openapi.command.undo.UnexpectedUndoException) UndoableAction(com.intellij.openapi.command.undo.UndoableAction) THashSet(gnu.trove.THashSet)

Example 48 with DocumentEx

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);
}
Also used : DocumentEx(com.intellij.openapi.editor.ex.DocumentEx) Document(com.intellij.openapi.editor.Document)

Example 49 with DocumentEx

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);
}
Also used : DocumentEx(com.intellij.openapi.editor.ex.DocumentEx) Document(com.intellij.openapi.editor.Document)

Example 50 with DocumentEx

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());
        }
    });
}
Also used : LightVirtualFile(com.intellij.testFramework.LightVirtualFile) MockVirtualFile(com.intellij.mock.MockVirtualFile) DocumentEx(com.intellij.openapi.editor.ex.DocumentEx) FileDocumentManagerAdapter(com.intellij.openapi.fileEditor.FileDocumentManagerAdapter) Document(com.intellij.openapi.editor.Document)

Aggregations

DocumentEx (com.intellij.openapi.editor.ex.DocumentEx)87 Document (com.intellij.openapi.editor.Document)12 NotNull (org.jetbrains.annotations.NotNull)8 RangeMarkerEx (com.intellij.openapi.editor.ex.RangeMarkerEx)7 Project (com.intellij.openapi.project.Project)7 TextRange (com.intellij.openapi.util.TextRange)7 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)7 PsiFile (com.intellij.psi.PsiFile)6 Nullable (org.jetbrains.annotations.Nullable)5 EditorEx (com.intellij.openapi.editor.ex.EditorEx)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 MockVirtualFile (com.intellij.mock.MockVirtualFile)3 FoldRegion (com.intellij.openapi.editor.FoldRegion)3 PsiDocumentManager (com.intellij.psi.PsiDocumentManager)3 DocumentWindow (com.intellij.injected.editor.DocumentWindow)2 DocumentBulkUpdateListener (com.intellij.openapi.editor.ex.DocumentBulkUpdateListener)2 DocumentImpl (com.intellij.openapi.editor.impl.DocumentImpl)2 DocumentMarkupModel (com.intellij.openapi.editor.impl.DocumentMarkupModel)2 RangeHighlighter (com.intellij.openapi.editor.markup.RangeHighlighter)2 FileDocumentManagerAdapter (com.intellij.openapi.fileEditor.FileDocumentManagerAdapter)2