Search in sources :

Example 26 with DocumentImpl

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

the class ConsoleViewImpl method runHeavyFilters.

private void runHeavyFilters(int line1, int endLine) {
    final int startLine = Math.max(0, line1);
    final Document document = myEditor.getDocument();
    final int startOffset = document.getLineStartOffset(startLine);
    String text = document.getText(new TextRange(startOffset, document.getLineEndOffset(endLine)));
    final Document documentCopy = new DocumentImpl(text, true);
    documentCopy.setReadOnly(true);
    myJLayeredPane.startUpdating();
    final int currentValue = myHeavyUpdateTicket;
    myHeavyAlarm.addRequest(() -> {
        if (!myFilters.shouldRunHeavy())
            return;
        try {
            myFilters.applyHeavyFilter(documentCopy, startOffset, startLine, additionalHighlight -> addFlushRequest(new FlushRunnable() {

                @Override
                public void doRun() {
                    if (myHeavyUpdateTicket != currentValue)
                        return;
                    TextAttributes additionalAttributes = additionalHighlight.getTextAttributes(null);
                    if (additionalAttributes != null) {
                        ResultItem item = additionalHighlight.getResultItems().get(0);
                        myHyperlinks.addHighlighter(item.getHighlightStartOffset(), item.getHighlightEndOffset(), additionalAttributes);
                    } else {
                        myHyperlinks.highlightHyperlinks(additionalHighlight, 0);
                    }
                }

                @Override
                public boolean equals(Object o) {
                    return this == o;
                }
            }, 0));
        } finally {
            if (myHeavyAlarm.getActiveRequestCount() <= 1) {
                // only the current request
                UIUtil.invokeLaterIfNeeded(() -> myJLayeredPane.finishUpdating());
            }
        }
    }, 0);
}
Also used : ResultItem(com.intellij.execution.filters.Filter.ResultItem) TextRange(com.intellij.openapi.util.TextRange) DocumentImpl(com.intellij.openapi.editor.impl.DocumentImpl) RelativePoint(com.intellij.ui.awt.RelativePoint)

Example 27 with DocumentImpl

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

the class KotlinFormattingModelBuilder method createModel.

@NotNull
@Override
public FormattingModel createModel(PsiElement element, CodeStyleSettings settings) {
    PsiFile containingFile = element.getContainingFile().getViewProvider().getPsi(KotlinLanguage.INSTANCE);
    KotlinBlock block = new KotlinBlock(containingFile.getNode(), NodeAlignmentStrategy.getNullStrategy(), Indent.getNoneIndent(), null, settings, KotlinSpacingRulesKt.createSpacingBuilder(settings, KotlinSpacingBuilderUtilImpl.INSTANCE));
    // it's needed until IDEA's issue with this document being created with wrong threading policy is fixed
    if (!element.isPhysical()) {
        FormattingDocumentModelImpl formattingDocumentModel = new FormattingDocumentModelImpl(new DocumentImpl(containingFile.getViewProvider().getContents(), true), containingFile);
        return new PsiBasedFormattingModel(containingFile, block, formattingDocumentModel);
    }
    return FormattingModelProvider.createFormattingModelForPsiFile(element.getContainingFile(), block, settings);
}
Also used : PsiBasedFormattingModel(com.intellij.psi.formatter.PsiBasedFormattingModel) PsiFile(com.intellij.psi.PsiFile) FormattingDocumentModelImpl(com.intellij.psi.formatter.FormattingDocumentModelImpl) DocumentImpl(com.intellij.openapi.editor.impl.DocumentImpl) NotNull(org.jetbrains.annotations.NotNull)

Example 28 with DocumentImpl

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

the class StudyUtils method deleteGuardedBlocks.

public static void deleteGuardedBlocks(@NotNull final Document document) {
    if (document instanceof DocumentImpl) {
        final DocumentImpl documentImpl = (DocumentImpl) document;
        List<RangeMarker> blocks = documentImpl.getGuardedBlocks();
        for (final RangeMarker block : blocks) {
            ApplicationManager.getApplication().invokeLater(() -> ApplicationManager.getApplication().runWriteAction(() -> document.removeGuardedBlock(block)));
        }
    }
}
Also used : RangeMarker(com.intellij.openapi.editor.RangeMarker) 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