Search in sources :

Example 51 with TextAttributes

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

the class CodeInsightTestFixtureImpl method testRainbow.

@Override
public void testRainbow(@NotNull String fileName, @NotNull String text, boolean isRainbowOn, boolean withColor) {
    final EditorColorsScheme globalScheme = EditorColorsManager.getInstance().getGlobalScheme();
    final boolean isRainbowOnInScheme = RainbowHighlighter.isRainbowEnabled(globalScheme, null);
    try {
        RainbowHighlighter.setRainbowEnabled(globalScheme, null, isRainbowOn);
        configureByText(fileName, text.replaceAll("<" + RAINBOW + "(\\scolor=\'[^\']*\')?>", "").replace("</" + RAINBOW + ">", ""));
        List<HighlightInfo> highlighting = ContainerUtil.filter(doHighlighting(), info -> info.type == RainbowHighlighter.RAINBOW_ELEMENT);
        assertEquals(text, getTagsFromSegments(myEditor.getDocument().getText(), highlighting, RAINBOW, highlightInfo -> {
            if (!withColor) {
                return null;
            }
            TextAttributes attributes = highlightInfo.getTextAttributes(null, null);
            String color = attributes == null ? "null" : attributes.getForegroundColor() == null ? "null" : Integer.toHexString(attributes.getForegroundColor().getRGB());
            return "color=\'" + color + "\'";
        }));
    } finally {
        RainbowHighlighter.setRainbowEnabled(globalScheme, null, isRainbowOnInScheme);
    }
}
Also used : com.intellij.openapi.util(com.intellij.openapi.util) UIUtil(com.intellij.util.ui.UIUtil) Lookup(com.intellij.codeInsight.lookup.Lookup) FindUsagesOptions(com.intellij.find.findUsages.FindUsagesOptions) com.intellij.testFramework(com.intellij.testFramework) FileComparisonFailure(com.intellij.rt.execution.junit.FileComparisonFailure) InspectionToolProvider(com.intellij.codeInspection.InspectionToolProvider) EditorUtil(com.intellij.openapi.editor.ex.util.EditorUtil) InspectionProfileImpl(com.intellij.codeInspection.ex.InspectionProfileImpl) PsiManagerEx(com.intellij.psi.impl.PsiManagerEx) StartupManagerEx(com.intellij.ide.startup.StartupManagerEx) ExtensionsArea(com.intellij.openapi.extensions.ExtensionsArea) DocumentMarkupModel(com.intellij.openapi.editor.impl.DocumentMarkupModel) com.intellij.openapi.fileEditor(com.intellij.openapi.fileEditor) PsiTreeUtil(com.intellij.psi.util.PsiTreeUtil) CodeFoldingManager(com.intellij.codeInsight.folding.CodeFoldingManager) RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) FileUtil(com.intellij.openapi.util.io.FileUtil) ComparisonFailure(junit.framework.ComparisonFailure) EditorActionManager(com.intellij.openapi.editor.actionSystem.EditorActionManager) Module(com.intellij.openapi.module.Module) StubUpdatingIndex(com.intellij.psi.stubs.StubUpdatingIndex) LanguageStructureViewBuilder(com.intellij.lang.LanguageStructureViewBuilder) DocumentWindow(com.intellij.injected.editor.DocumentWindow) LookupManager(com.intellij.codeInsight.lookup.LookupManager) DumpLookupElementWeights(com.intellij.internal.DumpLookupElementWeights) StructureViewBuilder(com.intellij.ide.structureView.StructureViewBuilder) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) FileElement(com.intellij.psi.impl.source.tree.FileElement) FacetManager(com.intellij.facet.FacetManager) HighlightUsagesAction(com.intellij.codeInsight.highlighting.actions.HighlightUsagesAction) UsageSearchContext(com.intellij.psi.search.UsageSearchContext) UncheckedIOException(java.io.UncheckedIOException) FindManager(com.intellij.find.FindManager) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) Stream(java.util.stream.Stream) ReadOnlyAttributeUtil(com.intellij.util.io.ReadOnlyAttributeUtil) StructureViewComponent(com.intellij.ide.structureView.newStructureView.StructureViewComponent) com.intellij.util(com.intellij.util) InspectionProjectProfileManager(com.intellij.profile.codeInspection.InspectionProjectProfileManager) java.util(java.util) GutterMark(com.intellij.codeInsight.daemon.GutterMark) com.intellij.openapi.editor(com.intellij.openapi.editor) UsageInfo(com.intellij.usageView.UsageInfo) DaemonCodeAnalyzer(com.intellij.codeInsight.daemon.DaemonCodeAnalyzer) SearchScope(com.intellij.psi.search.SearchScope) GotoClassModel2(com.intellij.ide.util.gotoByName.GotoClassModel2) CompletionProgressIndicator(com.intellij.codeInsight.completion.CompletionProgressIndicator) FileBasedIndex(com.intellij.util.indexing.FileBasedIndex) DebugUtil(com.intellij.psi.impl.DebugUtil) MockProgressIndicator(com.intellij.mock.MockProgressIndicator) StringUtil(com.intellij.openapi.util.text.StringUtil) AnalysisScope(com.intellij.analysis.AnalysisScope) IOException(java.io.IOException) Disposable(com.intellij.openapi.Disposable) File(java.io.File) ExtensionPointName(com.intellij.openapi.extensions.ExtensionPointName) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) Result(com.intellij.openapi.application.Result) InspectionToolWrapper(com.intellij.codeInspection.ex.InspectionToolWrapper) LocalInspectionTool(com.intellij.codeInspection.LocalInspectionTool) Assert(org.junit.Assert) IntentionListStep(com.intellij.codeInsight.intention.impl.IntentionListStep) LookupImpl(com.intellij.codeInsight.lookup.impl.LookupImpl) InlayInfo(com.intellij.codeInsight.hints.InlayInfo) com.intellij.testFramework.fixtures(com.intellij.testFramework.fixtures) HighlightSeverity(com.intellij.lang.annotation.HighlightSeverity) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager) InspectionProfileEntry(com.intellij.codeInspection.InspectionProfileEntry) ReadAction(com.intellij.openapi.application.ReadAction) InspectionManagerEx(com.intellij.codeInspection.ex.InspectionManagerEx) StartupManagerImpl(com.intellij.ide.startup.impl.StartupManagerImpl) PsiManagerImpl(com.intellij.psi.impl.PsiManagerImpl) EditorEx(com.intellij.openapi.editor.ex.EditorEx) MoveFilesOrDirectoriesProcessor(com.intellij.refactoring.move.moveFilesOrDirectories.MoveFilesOrDirectoriesProcessor) com.intellij.refactoring.rename(com.intellij.refactoring.rename) DumbService(com.intellij.openapi.project.DumbService) FileTypeManager(com.intellij.openapi.fileTypes.FileTypeManager) CompletionType(com.intellij.codeInsight.completion.CompletionType) com.intellij.codeInsight.daemon.impl(com.intellij.codeInsight.daemon.impl) FindManagerImpl(com.intellij.find.impl.FindManagerImpl) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) Collectors(java.util.stream.Collectors) Nullable(org.jetbrains.annotations.Nullable) ApplicationManager(com.intellij.openapi.application.ApplicationManager) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) ChooseByNamePopup(com.intellij.ide.util.gotoByName.ChooseByNamePopup) PsiFileImpl(com.intellij.psi.impl.source.PsiFileImpl) FileEditorManagerEx(com.intellij.openapi.fileEditor.ex.FileEditorManagerEx) WriteAction(com.intellij.openapi.application.WriteAction) PsiModificationTrackerImpl(com.intellij.psi.impl.PsiModificationTrackerImpl) RainbowHighlighter(com.intellij.codeHighlighting.RainbowHighlighter) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ContainerUtil(com.intellij.util.containers.ContainerUtil) TodoIndex(com.intellij.psi.impl.cache.impl.todo.TodoIndex) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) ReadonlyStatusHandlerImpl(com.intellij.openapi.vcs.readOnlyHandler.ReadonlyStatusHandlerImpl) ActionManagerEx(com.intellij.openapi.actionSystem.ex.ActionManagerEx) CacheManager(com.intellij.psi.impl.cache.CacheManager) Project(com.intellij.openapi.project.Project) DaemonCodeAnalyzerSettings(com.intellij.codeInsight.daemon.DaemonCodeAnalyzerSettings) InjectedLanguageUtil(com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil) DocumentImpl(com.intellij.openapi.editor.impl.DocumentImpl) Facet(com.intellij.facet.Facet) FindUsagesHandler(com.intellij.find.findUsages.FindUsagesHandler) ExtensionPoint(com.intellij.openapi.extensions.ExtensionPoint) InlayHintsChecker(com.intellij.testFramework.utils.inlays.InlayHintsChecker) TextEditorProvider(com.intellij.openapi.fileEditor.impl.text.TextEditorProvider) LookupElement(com.intellij.codeInsight.lookup.LookupElement) FileType(com.intellij.openapi.fileTypes.FileType) ChooseByNameBase(com.intellij.ide.util.gotoByName.ChooseByNameBase) EditorWindow(com.intellij.injected.editor.EditorWindow) TestOnly(org.jetbrains.annotations.TestOnly) CommandProcessor(com.intellij.openapi.command.CommandProcessor) ShowIntentionActionsHandler(com.intellij.codeInsight.intention.impl.ShowIntentionActionsHandler) TargetElementUtil(com.intellij.codeInsight.TargetElementUtil) com.intellij.openapi.vfs(com.intellij.openapi.vfs) CodeCompletionHandlerBase(com.intellij.codeInsight.completion.CodeCompletionHandlerBase) javax.swing(javax.swing) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme)

Example 52 with TextAttributes

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

the class EditorHyperlinkSupport method linkFollowed.

// todo fix link followed here!
private static void linkFollowed(Editor editor, Collection<RangeHighlighter> ranges, final RangeHighlighter link) {
    MarkupModelEx markupModel = (MarkupModelEx) editor.getMarkupModel();
    for (RangeHighlighter range : ranges) {
        TextAttributes oldAttr = range.getUserData(OLD_HYPERLINK_TEXT_ATTRIBUTES);
        if (oldAttr != null) {
            markupModel.setRangeHighlighterAttributes(range, oldAttr);
            range.putUserData(OLD_HYPERLINK_TEXT_ATTRIBUTES, null);
        }
        if (range == link) {
            range.putUserData(OLD_HYPERLINK_TEXT_ATTRIBUTES, range.getTextAttributes());
            markupModel.setRangeHighlighterAttributes(range, getFollowedHyperlinkAttributes(range));
        }
    }
    //refresh highlighter text attributes
    markupModel.addRangeHighlighter(0, 0, link.getLayer(), getHyperlinkAttributes(), HighlighterTargetArea.EXACT_RANGE).dispose();
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) MarkupModelEx(com.intellij.openapi.editor.ex.MarkupModelEx) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes)

Example 53 with TextAttributes

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

the class EditorHyperlinkSupport method highlightHyperlinks.

void highlightHyperlinks(@NotNull Filter.Result result, int offsetDelta) {
    Document document = myEditor.getDocument();
    for (Filter.ResultItem resultItem : result.getResultItems()) {
        int start = resultItem.getHighlightStartOffset() + offsetDelta;
        int end = resultItem.getHighlightEndOffset() + offsetDelta;
        if (start < 0 || end < start || end > document.getTextLength()) {
            continue;
        }
        TextAttributes attributes = resultItem.getHighlightAttributes();
        if (resultItem.getHyperlinkInfo() != null) {
            createHyperlink(start, end, attributes, resultItem.getHyperlinkInfo(), resultItem.getFollowedHyperlinkAttributes(), resultItem.getHighlighterLayer());
        } else if (attributes != null) {
            addHighlighter(start, end, attributes, resultItem.getHighlighterLayer());
        }
    }
}
Also used : Filter(com.intellij.execution.filters.Filter) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) Document(com.intellij.openapi.editor.Document) RelativePoint(com.intellij.ui.awt.RelativePoint)

Example 54 with TextAttributes

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

the class IterationStateTest method testColumnModeSelectionWithCurrentBreakpointHighlighting.

public void testColumnModeSelectionWithCurrentBreakpointHighlighting() {
    init("line1\n" + "line2");
    setColumnModeOn();
    Color breakpointColor = Color.RED;
    myFixture.getEditor().getMarkupModel().addLineHighlighter(0, HighlighterLayer.CARET_ROW + 1, new TextAttributes(null, breakpointColor, null, null, Font.PLAIN));
    Color currentDebuggingLineColor = Color.CYAN;
    myFixture.getEditor().getMarkupModel().addLineHighlighter(0, HighlighterLayer.SELECTION - 1, new TextAttributes(null, currentDebuggingLineColor, null, null, Font.PLAIN));
    mouse().pressAt(0, 4).dragTo(0, 6).release();
    verifySplitting(false, new Segment(0, 4, currentDebuggingLineColor), new Segment(4, 5, SELECTION_BACKGROUND), new Segment(5, 6, currentDebuggingLineColor), new Segment(6, 11, DEFAULT_BACKGROUND));
}
Also used : TextAttributes(com.intellij.openapi.editor.markup.TextAttributes)

Example 55 with TextAttributes

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

the class SoftWrapApplianceOnDocumentModificationTest method testLeadingTabWithShiftedWidth.

public void testLeadingTabWithShiftedWidth() throws IOException {
    // Inspired by IDEA-76353. The point is that we need to consider cached information about tab symbols width during logical
    // position to offset mapping
    String text = "\t test";
    init(15, text);
    ((EditorImpl) myEditor).setPrefixTextAndAttributes(" ", new TextAttributes());
    myEditor.getCaretModel().moveToOffset(text.length());
}
Also used : EditorImpl(com.intellij.openapi.editor.impl.EditorImpl) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes)

Aggregations

TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)205 EditorColorsManager (com.intellij.openapi.editor.colors.EditorColorsManager)40 EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)31 NotNull (org.jetbrains.annotations.NotNull)29 TextAttributesKey (com.intellij.openapi.editor.colors.TextAttributesKey)28 HighlightManager (com.intellij.codeInsight.highlighting.HighlightManager)26 RangeHighlighter (com.intellij.openapi.editor.markup.RangeHighlighter)26 SimpleTextAttributes (com.intellij.ui.SimpleTextAttributes)23 TextRange (com.intellij.openapi.util.TextRange)21 Nullable (org.jetbrains.annotations.Nullable)21 ArrayList (java.util.ArrayList)19 Editor (com.intellij.openapi.editor.Editor)18 Project (com.intellij.openapi.project.Project)17 PsiElement (com.intellij.psi.PsiElement)12 HighlightInfoType (com.intellij.codeInsight.daemon.impl.HighlightInfoType)10 VirtualFile (com.intellij.openapi.vfs.VirtualFile)10 JBColor (com.intellij.ui.JBColor)10 Document (com.intellij.openapi.editor.Document)9 ContainerUtil (com.intellij.util.containers.ContainerUtil)9 HighlightSeverity (com.intellij.lang.annotation.HighlightSeverity)8