Search in sources :

Example 6 with DocumentImpl

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

the class PsiDocumentManagerBase method beforeDocumentChange.

@Override
public void beforeDocumentChange(@NotNull DocumentEvent event) {
    if (myStopTrackingDocuments || myProject.isDisposed())
        return;
    final Document document = event.getDocument();
    VirtualFile virtualFile = FileDocumentManager.getInstance().getFile(document);
    boolean isRelevant = virtualFile != null && isRelevant(virtualFile);
    if (document instanceof DocumentImpl && !myUncommittedInfos.containsKey(document)) {
        myUncommittedInfos.put(document, new UncommittedInfo((DocumentImpl) document));
    }
    final FileViewProvider viewProvider = getCachedViewProvider(document);
    boolean inMyProject = viewProvider != null && viewProvider.getManager() == myPsiManager;
    if (!isRelevant || !inMyProject) {
        return;
    }
    final List<PsiFile> files = viewProvider.getAllFiles();
    PsiFile psiCause = null;
    for (PsiFile file : files) {
        if (file == null) {
            throw new AssertionError("View provider " + viewProvider + " (" + viewProvider.getClass() + ") returned null in its files array: " + files + " for file " + viewProvider.getVirtualFile());
        }
        if (PsiToDocumentSynchronizer.isInsideAtomicChange(file)) {
            psiCause = file;
        }
    }
    if (psiCause == null) {
        beforeDocumentChangeOnUnlockedDocument(viewProvider);
    }
    ((SingleRootFileViewProvider) viewProvider).beforeDocumentChanged(psiCause);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Document(com.intellij.openapi.editor.Document) FrozenDocument(com.intellij.openapi.editor.impl.FrozenDocument) DocumentImpl(com.intellij.openapi.editor.impl.DocumentImpl)

Example 7 with DocumentImpl

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

the class FoldingStressTest method stress.

private static void stress(final int len) {
    DocumentImpl doc = new DocumentImpl("0123456789\n123456789\n23456789");
    Editor editor = EditorFactory.getInstance().createEditor(doc);
    try {
        final FoldingModel model = editor.getFoldingModel();
        model.runBatchFoldingOperation(() -> {
            addAndCollapseFoldRegion(model, 0, len, "/*...*/");
            addAndCollapseFoldRegion(model, len + 2, len + 4, "/*...*/");
        });
        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 8 with DocumentImpl

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

the class DocumentTest method testModificationInsideCommandAssertion.

public void testModificationInsideCommandAssertion() {
    CommandProcessor commandProcessor = CommandProcessor.getInstance();
    assertTrue(!commandProcessor.isUndoTransparentActionInProgress() && commandProcessor.getCurrentCommand() == null);
    final Document doc = new DocumentImpl("xxx");
    mustThrow(() -> doc.insertString(1, "x"));
    mustThrow(() -> doc.deleteString(1, 2));
    mustThrow(() -> doc.replaceString(1, 2, "s"));
    WriteCommandAction.runWriteCommandAction(getProject(), () -> doc.insertString(1, "s"));
    WriteCommandAction.runWriteCommandAction(getProject(), () -> doc.deleteString(1, 2));
    WriteCommandAction.runWriteCommandAction(getProject(), () -> doc.replaceString(1, 2, "xxx"));
    WriteCommandAction.runWriteCommandAction(getProject(), () -> doc.setText("sss"));
    DocumentImpl console = new DocumentImpl("xxxx", true);
    // need no stinking command
    console.insertString(1, "s");
    console.deleteString(1, 2);
    console.replaceString(1, 2, "xxx");
    console.setText("sss");
}
Also used : CommandProcessor(com.intellij.openapi.command.CommandProcessor) DocumentImpl(com.intellij.openapi.editor.impl.DocumentImpl)

Example 9 with DocumentImpl

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

the class DocumentTest method testCorrectlyAddingAndRemovingListeners.

public void testCorrectlyAddingAndRemovingListeners() throws Exception {
    new WriteCommandAction.Simple(getProject()) {

        @Override
        protected void run() throws Throwable {
            final Document doc = new DocumentImpl("");
            final StringBuilder b = new StringBuilder();
            doc.addDocumentListener(new DocumentAdapter() {

                @Override
                public void beforeDocumentChange(DocumentEvent e) {
                    b.append("before1 ");
                }

                @Override
                public void documentChanged(DocumentEvent e) {
                    b.append("after1 ");
                }
            });
            doc.addDocumentListener(new DocumentAdapter() {

                @Override
                public void beforeDocumentChange(DocumentEvent event) {
                    doc.removeDocumentListener(this);
                }
            });
            doc.addDocumentListener(new DocumentAdapter() {

                @Override
                public void documentChanged(DocumentEvent e) {
                    doc.removeDocumentListener(this);
                }
            });
            doc.addDocumentListener(new DocumentAdapter() {

                @Override
                public void beforeDocumentChange(DocumentEvent e) {
                    b.append("before2 ");
                }

                @Override
                public void documentChanged(DocumentEvent e) {
                    b.append("after2 ");
                }
            });
            doc.setText("foo");
            assertEquals("before2 before1 after1 after2 ", b.toString());
        }
    }.execute().throwException();
}
Also used : DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) DocumentImpl(com.intellij.openapi.editor.impl.DocumentImpl)

Example 10 with DocumentImpl

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

the class EditorPlaceHolder method setContent.

public void setContent(final DiffContent content) {
    runRegisteredDisposables();
    myContent = content;
    if (myContent != null) {
        Document document = myContent.getDocument();
        if (myContent.isBinary() || document == null || myContent.getContentType() instanceof UIBasedFileType) {
            final VirtualFile file = myContent.getFile();
            if (file != null) {
                final FileEditorProvider[] providers = FileEditorProviderManager.getInstance().getProviders(getProject(), file);
                if (providers.length > 0) {
                    myFileEditor = providers[0].createEditor(getProject(), file);
                    if (myFileEditor instanceof TextEditor) {
                        myEditor = (EditorEx) ((TextEditor) myFileEditor).getEditor();
                        ContentDocumentListener.install(myContent, this);
                    }
                    myFileEditorProvider = providers[0];
                    addDisposable(new Disposable() {

                        @Override
                        public void dispose() {
                            myFileEditorProvider.disposeEditor(myFileEditor);
                            myFileEditor = null;
                            myFileEditorProvider = null;
                            myEditor = null;
                        }
                    });
                } else {
                    document = new DocumentImpl("Can not show", true);
                    final EditorFactory editorFactory = EditorFactory.getInstance();
                    myEditor = DiffUtil.createEditor(document, getProject(), true, content.getContentType());
                    addDisposable(new Disposable() {

                        public void dispose() {
                            editorFactory.releaseEditor(myEditor);
                            myEditor = null;
                        }
                    });
                }
            }
        } else {
            final EditorFactory editorFactory = EditorFactory.getInstance();
            myEditor = DiffUtil.createEditor(document, getProject(), false, content.getContentType());
            addDisposable(new Disposable() {

                public void dispose() {
                    editorFactory.releaseEditor(myEditor);
                    myEditor = null;
                }
            });
            ContentDocumentListener.install(myContent, this);
        }
    }
    fireContentChanged();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Disposable(com.intellij.openapi.Disposable) UIBasedFileType(com.intellij.openapi.fileTypes.UIBasedFileType) EditorFactory(com.intellij.openapi.editor.EditorFactory) TextEditor(com.intellij.openapi.fileEditor.TextEditor) FileEditorProvider(com.intellij.openapi.fileEditor.FileEditorProvider) Document(com.intellij.openapi.editor.Document) DocumentImpl(com.intellij.openapi.editor.impl.DocumentImpl)

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