Search in sources :

Example 31 with MarkupModelEx

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

the class LineMarkersUtil method setLineMarkersToEditor.

static void setLineMarkersToEditor(@NotNull Project project, @NotNull Document document, @NotNull Segment bounds, @NotNull Collection<LineMarkerInfo> markers, int group) {
    ApplicationManager.getApplication().assertIsDispatchThread();
    MarkupModelEx markupModel = (MarkupModelEx) DocumentMarkupModel.forDocument(document, project, true);
    HighlightersRecycler toReuse = new HighlightersRecycler();
    processLineMarkers(project, document, bounds, group, info -> {
        toReuse.recycleHighlighter(info.highlighter);
        return true;
    });
    if (LOG.isDebugEnabled()) {
        List<LineMarkerInfo> oldMarkers = DaemonCodeAnalyzerImpl.getLineMarkers(document, project);
        LOG.debug("LineMarkersUtil.setLineMarkersToEditor(markers: " + markers + ", group: " + group + "); oldMarkers: " + oldMarkers + "; reused: " + toReuse.forAllInGarbageBin().size());
    }
    for (final LineMarkerInfo info : markers) {
        PsiElement element = info.getElement();
        if (element == null) {
            continue;
        }
        TextRange textRange = element.getTextRange();
        if (textRange == null)
            continue;
        TextRange elementRange = InjectedLanguageManager.getInstance(project).injectedToHost(element, textRange);
        if (!TextRange.containsRange(bounds, elementRange)) {
            continue;
        }
        createOrReuseLineMarker(info, markupModel, toReuse);
    }
    for (RangeHighlighter highlighter : toReuse.forAllInGarbageBin()) {
        highlighter.dispose();
    }
}
Also used : LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) MarkupModelEx(com.intellij.openapi.editor.ex.MarkupModelEx) TextRange(com.intellij.openapi.util.TextRange) PsiElement(com.intellij.psi.PsiElement)

Example 32 with MarkupModelEx

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

the class LineMarkersUtil method addLineMarkerToEditorIncrementally.

static void addLineMarkerToEditorIncrementally(@NotNull Project project, @NotNull Document document, @NotNull LineMarkerInfo marker) {
    ApplicationManager.getApplication().assertIsDispatchThread();
    MarkupModelEx markupModel = (MarkupModelEx) DocumentMarkupModel.forDocument(document, project, true);
    LineMarkerInfo[] markerInTheWay = { null };
    boolean allIsClear = markupModel.processRangeHighlightersOverlappingWith(marker.startOffset, marker.endOffset, highlighter -> (markerInTheWay[0] = getLineMarkerInfo(highlighter)) == null);
    if (allIsClear) {
        createOrReuseLineMarker(marker, markupModel, null);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("LineMarkersUtil.addLineMarkerToEditorIncrementally: " + marker + " " + (allIsClear ? "created" : " (was not added because " + markerInTheWay[0] + " was in the way)"));
    }
}
Also used : LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) MarkupModelEx(com.intellij.openapi.editor.ex.MarkupModelEx)

Example 33 with MarkupModelEx

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

the class EmmetPreviewHint method createHint.

@NotNull
public static EmmetPreviewHint createHint(@NotNull final EditorEx parentEditor, @NotNull String templateText, @NotNull FileType fileType) {
    EditorFactory editorFactory = EditorFactory.getInstance();
    Document document = editorFactory.createDocument(templateText);
    final EditorEx previewEditor = (EditorEx) editorFactory.createEditor(document, parentEditor.getProject(), fileType, true);
    MarkupModelEx model = previewEditor.getMarkupModel();
    if (model instanceof EditorMarkupModel) {
        ((EditorMarkupModel) model).setErrorStripeVisible(true);
    }
    final EditorSettings settings = previewEditor.getSettings();
    settings.setLineNumbersShown(false);
    settings.setAdditionalLinesCount(1);
    settings.setAdditionalColumnsCount(1);
    settings.setRightMarginShown(false);
    settings.setFoldingOutlineShown(false);
    settings.setLineMarkerAreaShown(false);
    settings.setIndentGuidesShown(false);
    settings.setVirtualSpace(false);
    settings.setWheelFontChangeEnabled(false);
    settings.setAdditionalPageAtBottom(false);
    settings.setCaretRowShown(false);
    previewEditor.setCaretEnabled(false);
    previewEditor.setBorder(IdeBorderFactory.createEmptyBorder());
    JBPanel panel = new JBPanel(new BorderLayout()) {

        @NotNull
        @Override
        public Dimension getPreferredSize() {
            Dimension size = super.getPreferredSize();
            Dimension parentEditorSize = parentEditor.getScrollPane().getSize();
            int maxWidth = (int) parentEditorSize.getWidth() / 3;
            int maxHeight = (int) parentEditorSize.getHeight() / 2;
            final int width = settings.isUseSoftWraps() ? maxWidth : Math.min((int) size.getWidth(), maxWidth);
            final int height = Math.min((int) size.getHeight(), maxHeight);
            return new Dimension(width, height);
        }

        @NotNull
        @Override
        public Insets getInsets() {
            return new Insets(1, 2, 0, 0);
        }
    };
    panel.setBackground(previewEditor.getBackgroundColor());
    panel.add(previewEditor.getComponent(), BorderLayout.CENTER);
    return new EmmetPreviewHint(panel, previewEditor, parentEditor);
}
Also used : EditorEx(com.intellij.openapi.editor.ex.EditorEx) MarkupModelEx(com.intellij.openapi.editor.ex.MarkupModelEx) EditorMarkupModel(com.intellij.openapi.editor.ex.EditorMarkupModel) JBPanel(com.intellij.ui.components.JBPanel) HintHint(com.intellij.ui.HintHint) LightweightHint(com.intellij.ui.LightweightHint) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

MarkupModelEx (com.intellij.openapi.editor.ex.MarkupModelEx)33 RangeHighlighterEx (com.intellij.openapi.editor.ex.RangeHighlighterEx)17 Document (com.intellij.openapi.editor.Document)13 List (java.util.List)11 Project (com.intellij.openapi.project.Project)10 NotNull (org.jetbrains.annotations.NotNull)10 java.awt (java.awt)8 EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)7 DocumentMarkupModel (com.intellij.openapi.editor.impl.DocumentMarkupModel)7 RangeHighlighter (com.intellij.openapi.editor.markup.RangeHighlighter)7 PsiFile (com.intellij.psi.PsiFile)7 Processor (com.intellij.util.Processor)7 ContainerUtil (com.intellij.util.containers.ContainerUtil)7 Nullable (org.jetbrains.annotations.Nullable)7 GutterMark (com.intellij.codeInsight.daemon.GutterMark)6 java.util (java.util)6 HighlightSeverity (com.intellij.lang.annotation.HighlightSeverity)5 ApplicationManager (com.intellij.openapi.application.ApplicationManager)5 Editor (com.intellij.openapi.editor.Editor)5 RangeMarker (com.intellij.openapi.editor.RangeMarker)5