From a15b73c3b93ba8eb45989dfa9e7dbc7844dbd4df Mon Sep 17 00:00:00 2001 From: "Denis.Zhdanov" Date: Wed, 9 May 2012 13:58:05 +0400 Subject: [PATCH] IDEA-85697 Pale text color foreground combined with a pale highlighting color render the text unreadable --- .../openapi/editor/impl/IterationState.java | 43 ++++++++++++++++++- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/IterationState.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/IterationState.java index b7ce758466e9..39d4b554ede4 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/IterationState.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/IterationState.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,7 +36,46 @@ import java.util.Iterator; import java.util.List; public final class IterationState { + private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.editor.impl.IterationState"); + + private static final Comparator HIGHLIGHTER_COMPARATOR = new Comparator() { + @Override + public int compare(RangeHighlighterEx o1, RangeHighlighterEx o2) { + final int result = LayerComparator.INSTANCE.compare(o1, o2); + if (result != 0) { + return result; + } + + // There is a possible case when more than one highlighter target the same region (e.g. 'identifier under caret' and 'identifier'). + // We want to prefer the one that defines foreground color to the one that doesn't define (has either fore- or background colors + // while the other one has only foreground color). See IDEA-85697 for concrete example. + final TextAttributes a1 = o1.getTextAttributes(); + final TextAttributes a2 = o2.getTextAttributes(); + if (a1 == null ^ a2 == null) { + return a1 == null ? 1 : -1; + } + + if (a1 == null) { + return result; + } + + final Color fore1 = a1.getForegroundColor(); + final Color fore2 = a2.getForegroundColor(); + if (fore1 == null ^ fore2 == null) { + return fore1 == null ? 1 : -1; + } + + final Color back1 = a1.getBackgroundColor(); + final Color back2 = a2.getBackgroundColor(); + if (back1 == null ^ back2 == null) { + return back1 == null ? 1 : -1; + } + + return result; + } + }; + private final TextAttributes myMergedAttributes = new TextAttributes(); private final HighlighterIterator myHighlighterIterator; @@ -342,7 +381,7 @@ public final class IterationState { final int size = myCurrentHighlighters.size(); if (size > 1) { - ContainerUtil.quickSort(myCurrentHighlighters, LayerComparator.INSTANCE); + ContainerUtil.quickSort(myCurrentHighlighters, HIGHLIGHTER_COMPARATOR); } //noinspection ForLoopReplaceableByForEach