IDEA-242325 Incorrect speed search highlighting in structure dialog

GitOrigin-RevId: 801bc67304612c704311d936151a2cd694e87971
This commit is contained in:
Vassiliy.Kudryashov
2020-06-07 21:22:46 +00:00
committed by intellij-monorepo-bot
parent ff5308496d
commit 89873c8d4f
4 changed files with 13 additions and 3 deletions
@@ -970,9 +970,11 @@ public class GotoActionModel implements ChooseByNameModel, Comparator<Object>, D
SimpleTextAttributes plain = new SimpleTextAttributes(STYLE_PLAIN, fg);
SimpleTextAttributes highlighted = new SimpleTextAttributes(null, fg, null, STYLE_SEARCH_MATCH);
List<TextRange> fragments = new ArrayList<>();
nameComponent.setDynamicSearchMatchHighlighting(false);
if (selected) {
int matchStart = StringUtil.indexOfIgnoreCase(name, pattern, 0);
if (matchStart >= 0) {
nameComponent.setDynamicSearchMatchHighlighting(true);
fragments.add(TextRange.from(matchStart, pattern.length()));
}
}
@@ -96,6 +96,7 @@ public class SimpleColoredComponent extends JComponent implements Accessible, Co
private boolean myIconOnTheRight;
private boolean myTransparentIconBackground;
private boolean myDynamicSearchMatchHighlighting;
public SimpleColoredComponent() {
myFragments = new ArrayList<>(3);
@@ -879,7 +880,7 @@ public class SimpleColoredComponent extends JComponent implements Accessible, Co
Color fgColor;
if (attributes.isSearchMatch()) {
fgColor = new JBColor(Gray._50, Gray._0);
UIUtil.drawSearchMatch(g, x1, x2 + 1, height);
UIUtil.drawSearchMatch(g, x1, x2, height);
}
else if (attributes.isClickable()) {
boolean selected = UIUtil.getTreeSelectionBackground(true) == getBackground();
@@ -903,7 +904,7 @@ public class SimpleColoredComponent extends JComponent implements Accessible, Co
}
private boolean drawWithClipping(int index, Graphics2D g, Font font, float x1, float x2, float baseline) {
if (!SystemInfo.isMacOSCatalina) return false;
if (!SystemInfo.isMacOSCatalina || !myDynamicSearchMatchHighlighting) return false;
ColoredFragment fragment = myFragments.get(index);
if (!fragment.attributes.isSearchMatch()) return false;
ColoredFragment prevFragment = index > 0 ? myFragments.get(index - 1) : null;
@@ -921,7 +922,7 @@ public class SimpleColoredComponent extends JComponent implements Accessible, Co
+ (nextFragment != null ? nextFragment.text : "");
Graphics2D clippedGraphics = (Graphics2D)g.create();
try {
clippedGraphics.setClip(new Rectangle2D.Float(x1, 0, x2 - x1 + 1, getHeight()));
clippedGraphics.setClip(new Rectangle2D.Float(x1, 0, x2 - x1, getHeight()));
if (prevFragment != null) x1 -= computeStringWidth(prevFragment, font);
clippedGraphics.drawString(mergedText, x1, baseline);
@@ -1051,6 +1052,10 @@ public class SimpleColoredComponent extends JComponent implements Accessible, Co
myTransparentIconBackground = transparentIconBackground;
}
public void setDynamicSearchMatchHighlighting(boolean dynamicSearchMatchHighlighting) {
myDynamicSearchMatchHighlighting = dynamicSearchMatchHighlighting;
}
public static int getTextBaseLine(@NotNull FontMetrics metrics, final int height) {
// adding leading to ascent, just like in editor (leads to bad presentation for certain fonts with Oracle JDK, see IDEA-167541)
return (height - metrics.getHeight()) / 2 + metrics.getAscent() +
@@ -108,6 +108,7 @@ public final class SpeedSearchUtil {
}
final Iterable<TextRange> iterable = ((MinusculeMatcher)matcher).matchingFragments(text);
component.setDynamicSearchMatchHighlighting(iterable != null);
if (iterable != null) {
final Color fg = attributes.getFgColor();
final int style = attributes.getStyle();
@@ -468,9 +468,11 @@ public final class SearchUtil {
return;
}
if (filter == null || filter.length() == 0) {
textRenderer.setDynamicSearchMatchHighlighting(false);
textRenderer.append(text, new SimpleTextAttributes(background, foreground, JBColor.RED, style));
}
else {
textRenderer.setDynamicSearchMatchHighlighting(true);
//markup
ObjectOpenHashSet<String> quoted = new ObjectOpenHashSet<>();
filter = processFilter(quoteStrictOccurrences(text, filter), quoted);