Search in sources :

Example 21 with DocumentImpl

use of com.intellij.openapi.editor.impl.DocumentImpl in project intellij-community by JetBrains.

the class DocumentTest method testEmptyDocumentLineCount.

public void testEmptyDocumentLineCount() {
    WriteCommandAction.runWriteCommandAction(ourProject, () -> {
        DocumentImpl document = new DocumentImpl("");
        assertEquals(0, document.getLineCount());
        document.insertString(0, "a");
        assertEquals(1, document.getLineCount());
        document.deleteString(0, 1);
        assertEquals(0, document.getLineCount());
    });
}
Also used : DocumentImpl(com.intellij.openapi.editor.impl.DocumentImpl)

Example 22 with DocumentImpl

use of com.intellij.openapi.editor.impl.DocumentImpl in project intellij-community by JetBrains.

the class FoldingStressTest method testStress8.

public void testStress8() throws Exception {
    DocumentImpl doc = new DocumentImpl("0123456789\n123456789\n23456789");
    Editor editor = EditorFactory.getInstance().createEditor(doc);
    try {
        final FoldingModel model = editor.getFoldingModel();
        model.runBatchFoldingOperation(() -> {
            addAndCollapseFoldRegion(model, 0, 8, "/*...*/");
            addAndCollapseFoldRegion(model, 10, 12, "/*...*/");
        });
        assertEquals(10, editor.logicalPositionToOffset(new LogicalPosition(0, 10)));
        for (int line = 0; line <= 3; line++) {
            for (int column = 0; column <= 100; column++) {
                LogicalPosition log = new LogicalPosition(line, column);
                editor.logicalToVisualPosition(log);
            }
        }
    } finally {
        EditorFactory.getInstance().releaseEditor(editor);
    }
}
Also used : DocumentImpl(com.intellij.openapi.editor.impl.DocumentImpl)

Example 23 with DocumentImpl

use of com.intellij.openapi.editor.impl.DocumentImpl in project intellij-community by JetBrains.

the class ChangesDiffCalculatorTest method doTest.

private static void doTest(@NotNull String before, @NotNull String current, @NotNull TextRange... expectedRanges) {
    DocumentImpl beforeDocument = new DocumentImpl(before);
    DocumentImpl currentDocument = new DocumentImpl(current);
    List<TextRange> actualRanges = ChangesDiffCalculator.calculateDiff(beforeDocument, currentDocument);
    assertEquals(Arrays.asList(expectedRanges), actualRanges);
}
Also used : TextRange(com.intellij.openapi.util.TextRange) DocumentImpl(com.intellij.openapi.editor.impl.DocumentImpl)

Example 24 with DocumentImpl

use of com.intellij.openapi.editor.impl.DocumentImpl in project intellij-community by JetBrains.

the class LightPlatformCodeInsightTestCase method checkResultByTextWithoutPSI.

protected static void checkResultByTextWithoutPSI(final String message, @NotNull final Editor editor, @NotNull final String fileText, final boolean ignoreTrailingSpaces, final String filePath) {
    ApplicationManager.getApplication().runWriteAction(() -> {
        final Document fakeDocument = EditorFactory.getInstance().createDocument(fileText);
        if (ignoreTrailingSpaces) {
            ((DocumentImpl) fakeDocument).stripTrailingSpaces(getProject());
        }
        EditorTestUtil.CaretAndSelectionState carets = EditorTestUtil.extractCaretAndSelectionMarkers(fakeDocument);
        String newFileText = fakeDocument.getText();
        String fileText1 = editor.getDocument().getText();
        String failMessage = getMessage("Text mismatch", message);
        if (filePath != null && !newFileText.equals(fileText1)) {
            throw new FileComparisonFailure(failMessage, newFileText, fileText1, filePath);
        }
        assertEquals(failMessage, newFileText, fileText1);
        EditorTestUtil.verifyCaretAndSelectionState(editor, carets, message);
    });
}
Also used : Document(com.intellij.openapi.editor.Document) DocumentImpl(com.intellij.openapi.editor.impl.DocumentImpl) FileComparisonFailure(com.intellij.rt.execution.junit.FileComparisonFailure)

Example 25 with DocumentImpl

use of com.intellij.openapi.editor.impl.DocumentImpl in project intellij-community by JetBrains.

the class LightPlatformCodeInsightTestCase method configureFromFileText.

/**
   * Same as configureByFile but text is provided directly.
   * @param fileName - name of the file.
   * @param fileText - data file text.
   * @param checkCaret - if true, if will be verified that file contains at least one caret or selection marker
   */
@NotNull
protected static Document configureFromFileText(@NonNls @NotNull final String fileName, @NonNls @NotNull final String fileText, boolean checkCaret) {
    return new WriteCommandAction<Document>(null) {

        @Override
        protected void run(@NotNull Result<Document> result) throws Throwable {
            final Document fakeDocument = new DocumentImpl(fileText);
            EditorTestUtil.CaretAndSelectionState caretsState = EditorTestUtil.extractCaretAndSelectionMarkers(fakeDocument);
            if (checkCaret) {
                assertTrue("No caret specified in " + fileName, caretsState.hasExplicitCaret());
            }
            String newFileText = fakeDocument.getText();
            Document document;
            try {
                document = setupFileEditorAndDocument(fileName, newFileText);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            EditorTestUtil.setCaretsAndSelection(myEditor, caretsState);
            setupEditorForInjectedLanguage();
            result.setResult(document);
        }
    }.execute().getResultObject();
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) IOException(java.io.IOException) Document(com.intellij.openapi.editor.Document) NotNull(org.jetbrains.annotations.NotNull) DocumentImpl(com.intellij.openapi.editor.impl.DocumentImpl) Result(com.intellij.openapi.application.Result) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

DocumentImpl (com.intellij.openapi.editor.impl.DocumentImpl)28 Document (com.intellij.openapi.editor.Document)12 NotNull (org.jetbrains.annotations.NotNull)6 RangeMarker (com.intellij.openapi.editor.RangeMarker)4 TextRange (com.intellij.openapi.util.TextRange)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 PsiFile (com.intellij.psi.PsiFile)3 FrozenDocument (com.intellij.openapi.editor.impl.FrozenDocument)2 PsiDocumentManager (com.intellij.psi.PsiDocumentManager)2 FileComparisonFailure (com.intellij.rt.execution.junit.FileComparisonFailure)2 RelativePoint (com.intellij.ui.awt.RelativePoint)2 IncorrectOperationException (com.intellij.util.IncorrectOperationException)2 InlayInfo (com.intellij.codeInsight.hints.InlayInfo)1 ResultItem (com.intellij.execution.filters.Filter.ResultItem)1 HyperlinkInfo (com.intellij.execution.filters.HyperlinkInfo)1 DocumentWindow (com.intellij.injected.editor.DocumentWindow)1 JSTestOptions (com.intellij.lang.javascript.JSTestOptions)1 Disposable (com.intellij.openapi.Disposable)1 AnAction (com.intellij.openapi.actionSystem.AnAction)1 Result (com.intellij.openapi.application.Result)1