Search in sources :

Example 21 with MarkupModel

use of com.intellij.openapi.editor.markup.MarkupModel in project intellij-community by JetBrains.

the class InplaceIntroduceParameterPopup method updateTitle.

@Override
protected void updateTitle(@Nullable final PsiVariable variable, final String value) {
    final PsiElement declarationScope = variable != null ? ((PsiParameter) variable).getDeclarationScope() : null;
    if (declarationScope instanceof PsiMethod) {
        final PsiMethod psiMethod = (PsiMethod) declarationScope;
        final StringBuilder buf = new StringBuilder();
        buf.append(psiMethod.getName()).append(" (");
        boolean frst = true;
        final List<TextRange> ranges2Remove = new ArrayList<>();
        TextRange addedRange = null;
        for (PsiParameter parameter : psiMethod.getParameterList().getParameters()) {
            if (frst) {
                frst = false;
            } else {
                buf.append(", ");
            }
            int startOffset = buf.length();
            if (myMustBeFinal || myPanel.isGenerateFinal()) {
                buf.append("final ");
            }
            buf.append(parameter.getType().getPresentableText()).append(" ").append(variable == parameter ? value : parameter.getName());
            int endOffset = buf.length();
            if (variable == parameter) {
                addedRange = new TextRange(startOffset, endOffset);
            } else if (myPanel.isParamToRemove(parameter)) {
                ranges2Remove.add(new TextRange(startOffset, endOffset));
            }
        }
        buf.append(")");
        setPreviewText(buf.toString());
        final MarkupModel markupModel = DocumentMarkupModel.forDocument(getPreviewEditor().getDocument(), myProject, true);
        markupModel.removeAllHighlighters();
        for (TextRange textRange : ranges2Remove) {
            markupModel.addRangeHighlighter(textRange.getStartOffset(), textRange.getEndOffset(), 0, getTestAttributesForRemoval(), HighlighterTargetArea.EXACT_RANGE);
        }
        markupModel.addRangeHighlighter(addedRange.getStartOffset(), addedRange.getEndOffset(), 0, getTextAttributesForAdd(), HighlighterTargetArea.EXACT_RANGE);
        revalidate();
    }
}
Also used : ArrayList(java.util.ArrayList) TIntArrayList(gnu.trove.TIntArrayList) TextRange(com.intellij.openapi.util.TextRange) DocumentMarkupModel(com.intellij.openapi.editor.impl.DocumentMarkupModel) MarkupModel(com.intellij.openapi.editor.markup.MarkupModel)

Example 22 with MarkupModel

use of com.intellij.openapi.editor.markup.MarkupModel in project intellij-community by JetBrains.

the class DaemonRespondToChangesTest method testRangeHighlightersDoNotGetStuckForever.

public void testRangeHighlightersDoNotGetStuckForever() throws Throwable {
    configureByText(StdFileTypes.JAVA, "class S { void ffffff() {fff<caret>fff();}}");
    List<HighlightInfo> infos = highlightErrors();
    assertEmpty(infos);
    MarkupModel markup = DocumentMarkupModel.forDocument(myEditor.getDocument(), getProject(), true);
    final TextRange[] highlightersBefore = getHighlightersTextRange(markup);
    type("%%%%");
    highlightErrors();
    backspace();
    backspace();
    backspace();
    backspace();
    infos = highlightErrors();
    assertEmpty(infos);
    final TextRange[] highlightersAfter = getHighlightersTextRange(markup);
    assertEquals(highlightersBefore.length, highlightersAfter.length);
    for (int i = 0; i < highlightersBefore.length; i++) {
        TextRange before = highlightersBefore[i];
        TextRange after = highlightersAfter[i];
        assertEquals(before.getStartOffset(), after.getStartOffset());
        assertEquals(before.getEndOffset(), after.getEndOffset());
    }
}
Also used : TextRange(com.intellij.openapi.util.TextRange) ProperTextRange(com.intellij.openapi.util.ProperTextRange) DocumentMarkupModel(com.intellij.openapi.editor.impl.DocumentMarkupModel) MarkupModel(com.intellij.openapi.editor.markup.MarkupModel) LightweightHint(com.intellij.ui.LightweightHint)

Example 23 with MarkupModel

use of com.intellij.openapi.editor.markup.MarkupModel in project intellij-code-outline by sitano.

the class CodeOutlinePanel method highlightCurrentLine.

/**
 * Highlights the line specified by <code>lastMousePoint</code>. This method
 * does nothing if <code>lastMousePoint</code> is <code>null</code>.
 */
private void highlightCurrentLine() {
    if (lastMousePoint == null)
        return;
    clearHighlightedLine();
    MarkupModel mm = editor.getMarkupModel();
    int line = getLineFromMousePointY(lastMousePoint.y);
    if (line >= 0 && line < editor.getDocument().getLineCount()) {
        highlighter = mm.addLineHighlighter(line, 100, CURRENTLINE_ATTRIBUTES);
    }
}
Also used : MarkupModel(com.intellij.openapi.editor.markup.MarkupModel)

Aggregations

MarkupModel (com.intellij.openapi.editor.markup.MarkupModel)23 DocumentMarkupModel (com.intellij.openapi.editor.impl.DocumentMarkupModel)12 RangeHighlighter (com.intellij.openapi.editor.markup.RangeHighlighter)10 Editor (com.intellij.openapi.editor.Editor)8 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)8 Project (com.intellij.openapi.project.Project)8 TextRange (com.intellij.openapi.util.TextRange)8 List (java.util.List)6 NotNull (org.jetbrains.annotations.NotNull)5 Document (com.intellij.openapi.editor.Document)4 EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)4 ArrayList (java.util.ArrayList)4 javax.swing (javax.swing)4 Segment (com.intellij.openapi.util.Segment)3 HighlightInfo (com.intellij.codeInsight.daemon.impl.HighlightInfo)2 EditorFactory (com.intellij.openapi.editor.EditorFactory)2 EditorEx (com.intellij.openapi.editor.ex.EditorEx)2 MarkupModelEx (com.intellij.openapi.editor.ex.MarkupModelEx)2 RangeHighlighterEx (com.intellij.openapi.editor.ex.RangeHighlighterEx)2 EditorUtil (com.intellij.openapi.editor.ex.util.EditorUtil)2