Search in sources :

Example 66 with DocumentEx

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

the class FoldingModelSupport method addFolding.

@Nullable
public static FoldRegion addFolding(@NotNull EditorEx editor, int start, int end, boolean expanded) {
    DocumentEx document = editor.getDocument();
    final int startOffset = document.getLineStartOffset(start);
    final int endOffset = document.getLineEndOffset(end - 1);
    FoldRegion value = editor.getFoldingModel().addFoldRegion(startOffset, endOffset, PLACEHOLDER);
    if (value != null)
        value.setExpanded(expanded);
    return value;
}
Also used : DocumentEx(com.intellij.openapi.editor.ex.DocumentEx) FoldRegion(com.intellij.openapi.editor.FoldRegion) Nullable(org.jetbrains.annotations.Nullable)

Example 67 with DocumentEx

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

the class UpdateHighlightersUtil method updateHighlightersByTyping.

static void updateHighlightersByTyping(@NotNull Project project, @NotNull DocumentEvent e) {
    ApplicationManager.getApplication().assertIsDispatchThread();
    final Document document = e.getDocument();
    if (document instanceof DocumentEx && ((DocumentEx) document).isInBulkUpdate())
        return;
    final MarkupModel markup = DocumentMarkupModel.forDocument(document, project, true);
    assertMarkupConsistent(markup, project);
    final int start = e.getOffset() - 1;
    final int end = start + e.getOldLength();
    final List<HighlightInfo> toRemove = new ArrayList<>();
    DaemonCodeAnalyzerEx.processHighlights(document, project, null, start, end, info -> {
        if (!info.needUpdateOnTyping())
            return true;
        RangeHighlighter highlighter = info.getHighlighter();
        int highlighterStart = highlighter.getStartOffset();
        int highlighterEnd = highlighter.getEndOffset();
        if (info.isAfterEndOfLine()) {
            if (highlighterStart < document.getTextLength()) {
                highlighterStart += 1;
            }
            if (highlighterEnd < document.getTextLength()) {
                highlighterEnd += 1;
            }
        }
        if (!highlighter.isValid() || start < highlighterEnd && highlighterStart <= end) {
            toRemove.add(info);
        }
        return true;
    });
    for (HighlightInfo info : toRemove) {
        if (!info.getHighlighter().isValid() || info.type.equals(HighlightInfoType.WRONG_REF)) {
            info.getHighlighter().dispose();
        }
    }
    assertMarkupConsistent(markup, project);
    if (!toRemove.isEmpty()) {
        disableWhiteSpaceOptimization(document);
    }
}
Also used : DocumentEx(com.intellij.openapi.editor.ex.DocumentEx) Document(com.intellij.openapi.editor.Document) DocumentMarkupModel(com.intellij.openapi.editor.impl.DocumentMarkupModel)

Example 68 with DocumentEx

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

the class PrintManager method doInitTextPainter.

private static TextPainter doInitTextPainter(final PsiFile psiFile) {
    VirtualFile virtualFile = psiFile.getVirtualFile();
    if (virtualFile == null)
        return null;
    DocumentEx doc = (DocumentEx) PsiDocumentManager.getInstance(psiFile.getProject()).getDocument(psiFile);
    if (doc == null)
        return null;
    EditorHighlighter highlighter = HighlighterFactory.createHighlighter(psiFile.getProject(), virtualFile);
    highlighter.setText(doc.getCharsSequence());
    return new TextPainter(doc, highlighter, virtualFile.getPresentableUrl(), virtualFile.getPresentableName(), psiFile, psiFile.getFileType());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DocumentEx(com.intellij.openapi.editor.ex.DocumentEx) EditorHighlighter(com.intellij.openapi.editor.highlighter.EditorHighlighter)

Example 69 with DocumentEx

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

the class DocumentUtil method executeInBulk.

/**
   * Ensures that given task is executed when given document is at the given 'in bulk' mode.
   * 
   * @param document       target document
   * @param executeInBulk  {@code true} to force given document to be in bulk mode when given task is executed;
   *                       {@code false} to force given document to be <b>not</b> in bulk mode when given task is executed
   * @param task           task to execute
   */
public static void executeInBulk(@NotNull Document document, final boolean executeInBulk, @NotNull Runnable task) {
    if (!(document instanceof DocumentEx)) {
        task.run();
        return;
    }
    DocumentEx documentEx = (DocumentEx) document;
    if (executeInBulk == documentEx.isInBulkUpdate()) {
        task.run();
        return;
    }
    documentEx.setInBulkUpdate(executeInBulk);
    try {
        task.run();
    } finally {
        documentEx.setInBulkUpdate(!executeInBulk);
    }
}
Also used : DocumentEx(com.intellij.openapi.editor.ex.DocumentEx)

Example 70 with DocumentEx

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

the class ConsoleViewImpl method highlightHyperlinksAndFoldings.

private void highlightHyperlinksAndFoldings(int startLine) {
    ApplicationManager.getApplication().assertIsDispatchThread();
    boolean canHighlightHyperlinks = !myFilters.isEmpty();
    if (!canHighlightHyperlinks && myUpdateFoldingsEnabled) {
        return;
    }
    DocumentEx document = myEditor.getDocument();
    if (document.getTextLength() == 0)
        return;
    int endLine = Math.max(0, document.getLineCount() - 1);
    if (canHighlightHyperlinks) {
        myHyperlinks.highlightHyperlinks(myFilters, startLine, endLine);
    }
    if (myAllowHeavyFilters && myFilters.isAnyHeavy() && myFilters.shouldRunHeavy()) {
        runHeavyFilters(startLine, endLine);
    }
    if (myUpdateFoldingsEnabled) {
        updateFoldings(startLine, endLine);
    }
}
Also used : DocumentEx(com.intellij.openapi.editor.ex.DocumentEx) RelativePoint(com.intellij.ui.awt.RelativePoint)

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