Search in sources :

Example 16 with DocumentEx

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

the class EditorImplTest method testCaretMergeDuringBulkModeDocumentUpdate.

public void testCaretMergeDuringBulkModeDocumentUpdate() throws Exception {
    initText("a<selection>bcdef<caret></selection>g\n" + "a<selection>bcdef<caret></selection>g");
    runWriteCommand(() -> {
        DocumentEx document = (DocumentEx) myEditor.getDocument();
        DocumentUtil.executeInBulk(document, true, () -> {
            // delete selected text
            document.deleteString(1, 6);
            document.deleteString(4, 9);
        });
    });
    checkResultByText("a<caret>g\n" + "a<caret>g");
}
Also used : DocumentEx(com.intellij.openapi.editor.ex.DocumentEx)

Example 17 with DocumentEx

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

the class EditorImplTest method testSoftWrapModeUpdateDuringBulkModeChange.

public void testSoftWrapModeUpdateDuringBulkModeChange() throws Exception {
    initText("long long line<caret>");
    configureSoftWraps(12);
    DocumentEx document = (DocumentEx) myEditor.getDocument();
    runWriteCommand(() -> {
        DocumentUtil.executeInBulk(document, true, () -> {
            document.replaceString(4, 5, "-");
        });
    });
    assertEquals(new VisualPosition(1, 5), myEditor.getCaretModel().getVisualPosition());
}
Also used : DocumentEx(com.intellij.openapi.editor.ex.DocumentEx)

Example 18 with DocumentEx

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

the class EditorImplTest method testSuccessiveBulkModeOperations.

public void testSuccessiveBulkModeOperations() throws Exception {
    initText("some text");
    DocumentEx document = (DocumentEx) myEditor.getDocument();
    runWriteCommand(() -> {
        DocumentUtil.executeInBulk(document, true, () -> {
            document.replaceString(4, 5, "-");
        });
        myEditor.getCaretModel().moveToOffset(9);
        DocumentUtil.executeInBulk(document, true, () -> {
            document.replaceString(4, 5, "+");
        });
    });
    checkResultByText("some+text<caret>");
}
Also used : DocumentEx(com.intellij.openapi.editor.ex.DocumentEx)

Example 19 with DocumentEx

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

the class PsiDocumentManagerImplTest method testBackgroundCommitDoesNotChokeByWildChangesWhichInvalidatePsiFile.

public void testBackgroundCommitDoesNotChokeByWildChangesWhichInvalidatePsiFile() throws Exception {
    @Language("JAVA") String text = "\n\nclass X {\npublic static final String string =null;\n public void x() {}\n}";
    VirtualFile virtualFile = getVirtualFile(createTempFile("X.java", text));
    PsiFile file = getPsiManager().findFile(virtualFile);
    DocumentEx document = (DocumentEx) file.getViewProvider().getDocument();
    PsiDocumentManager pdm = PsiDocumentManager.getInstance(myProject);
    pdm.commitAllDocuments();
    WriteCommandAction.runWriteCommandAction(null, () -> {
        try {
            virtualFile.setBinaryContent("\n txt txt txt".getBytes("UTF-8"));
            virtualFile.rename(this, "X.txt");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    });
    DocumentCommitThread.getInstance().waitForAllCommits();
    assertTrue(pdm.isCommitted(document));
    assertFalse(file.isValid());
    WriteCommandAction.runWriteCommandAction(null, () -> document.replaceString(0, document.getTextLength(), "xxxxxxxxxxxxxxxxxxxx"));
    pdm.commitAllDocuments();
    assertTrue(pdm.isCommitted(document));
    PsiFile file2 = getPsiManager().findFile(virtualFile);
    assertEquals(PlainTextLanguage.INSTANCE, file2.getLanguage());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) DocumentEx(com.intellij.openapi.editor.ex.DocumentEx) Language(org.intellij.lang.annotations.Language) PlainTextLanguage(com.intellij.openapi.fileTypes.PlainTextLanguage) MockPsiFile(com.intellij.mock.MockPsiFile) IOException(java.io.IOException)

Example 20 with DocumentEx

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

the class RangeMarkerTest method testE6.

public void testE6() {
    DocumentEx document = (DocumentEx) EditorFactory.getInstance().createDocument(StringUtil.repeatSymbol(' ', 10));
    List<RangeMarker> mm = add(document, 4, 8, 4, 4, 4, 9, 0, 2, 6, 8);
    edit(document, 3, 2, 0);
}
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