Search in sources :

Example 51 with DocumentEx

use of com.intellij.openapi.editor.ex.DocumentEx in project intellij-community by JetBrains.

the class FileDocumentManagerImplTest method testSaveDocument_DoNotSaveIfModStampEqualsToFile.

public void testSaveDocument_DoNotSaveIfModStampEqualsToFile() throws Exception {
    final VirtualFile file = createFile();
    final DocumentEx document = (DocumentEx) myDocumentManager.getDocument(file);
    assertNotNull(file.toString(), document);
    WriteCommandAction.runWriteCommandAction(myProject, () -> {
        document.insertString(0, "zzz");
        document.setModificationStamp(file.getModificationStamp());
    });
    getProject().getMessageBus().connect(getTestRootDisposable()).subscribe(AppTopics.FILE_DOCUMENT_SYNC, new FileDocumentManagerAdapter() {

        @Override
        public void beforeDocumentSaving(@NotNull Document documentToSave) {
            assertNotSame(document, documentToSave);
        }
    });
    myDocumentManager.saveDocument(document);
}
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)

Example 52 with DocumentEx

use of com.intellij.openapi.editor.ex.DocumentEx in project intellij-community by JetBrains.

the class FileDocumentManagerImplTest method testExternalReplaceWithTheSameText.

public void testExternalReplaceWithTheSameText() throws Exception {
    final VirtualFile file = createFile();
    long modificationStamp = file.getModificationStamp();
    DocumentEx document = (DocumentEx) myDocumentManager.getDocument(file);
    FileUtil.writeToFile(new File(file.getPath()), "xxx");
    file.refresh(false, false);
    assertNotNull(file.toString(), document);
    assertNotSame(file.getModificationStamp(), modificationStamp);
    assertEquals(file.getModificationStamp(), document.getModificationStamp());
}
Also used : LightVirtualFile(com.intellij.testFramework.LightVirtualFile) MockVirtualFile(com.intellij.mock.MockVirtualFile) DocumentEx(com.intellij.openapi.editor.ex.DocumentEx) PsiFile(com.intellij.psi.PsiFile) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) MockVirtualFile(com.intellij.mock.MockVirtualFile) File(java.io.File)

Example 53 with DocumentEx

use of com.intellij.openapi.editor.ex.DocumentEx in project intellij-community by JetBrains.

the class ApplyPatchChange method calcPatchInnerDifferences.

@Nullable
private static List<DiffFragment> calcPatchInnerDifferences(@NotNull PatchChangeBuilder.Hunk hunk, @NotNull ApplyPatchViewer viewer) {
    LineRange deletionRange = hunk.getPatchDeletionRange();
    LineRange insertionRange = hunk.getPatchInsertionRange();
    if (deletionRange.isEmpty() || insertionRange.isEmpty())
        return null;
    try {
        DocumentEx patchDocument = viewer.getPatchEditor().getDocument();
        CharSequence deleted = DiffUtil.getLinesContent(patchDocument, deletionRange.start, deletionRange.end);
        CharSequence inserted = DiffUtil.getLinesContent(patchDocument, insertionRange.start, insertionRange.end);
        return ByWord.compare(deleted, inserted, ComparisonPolicy.DEFAULT, DumbProgressIndicator.INSTANCE);
    } catch (DiffTooBigException ignore) {
        return null;
    }
}
Also used : DocumentEx(com.intellij.openapi.editor.ex.DocumentEx) DiffTooBigException(com.intellij.diff.comparison.DiffTooBigException) Nullable(org.jetbrains.annotations.Nullable)

Example 54 with DocumentEx

use of com.intellij.openapi.editor.ex.DocumentEx in project intellij-community by JetBrains.

the class EditorImplTest method testChangingHighlightersInBulkModeListener.

public void testChangingHighlightersInBulkModeListener() throws Exception {
    DocumentBulkUpdateListener.Adapter listener = new DocumentBulkUpdateListener.Adapter() {

        @Override
        public void updateFinished(@NotNull Document doc) {
            if (doc == myEditor.getDocument()) {
                myEditor.getMarkupModel().addRangeHighlighter(7, 8, 0, null, HighlighterTargetArea.EXACT_RANGE);
            }
        }
    };
    getProject().getMessageBus().connect(getTestRootDisposable()).subscribe(DocumentBulkUpdateListener.TOPIC, listener);
    initText("abcdef");
    DocumentEx document = (DocumentEx) myEditor.getDocument();
    runWriteCommand(() -> {
        DocumentUtil.executeInBulk(document, true, () -> {
            document.insertString(3, "\n\n");
        });
    });
    RangeHighlighter[] highlighters = myEditor.getMarkupModel().getAllHighlighters();
    assertEquals(1, highlighters.length);
    assertEquals(7, highlighters[0].getStartOffset());
    assertEquals(8, highlighters[0].getEndOffset());
}
Also used : DocumentEx(com.intellij.openapi.editor.ex.DocumentEx) RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) NotNull(org.jetbrains.annotations.NotNull) DocumentBulkUpdateListener(com.intellij.openapi.editor.ex.DocumentBulkUpdateListener)

Example 55 with DocumentEx

use of com.intellij.openapi.editor.ex.DocumentEx in project intellij-community by JetBrains.

the class EditorImplTest method testUpdatingCaretPositionAfterBulkMode.

public void testUpdatingCaretPositionAfterBulkMode() throws Exception {
    initText("a<caret>bc");
    runWriteCommand(() -> {
        DocumentEx document = (DocumentEx) myEditor.getDocument();
        DocumentUtil.executeInBulk(document, true, () -> {
            // we're changing number of visual lines, and invalidating text layout for caret line
            document.insertString(0, "\n ");
        });
    });
    checkResultByText("\n a<caret>bc");
}
Also used : DocumentEx(com.intellij.openapi.editor.ex.DocumentEx)

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